本帖最后由 jackz007 于 2021-4-4 20:41 编辑 def prime(n):
r = False
if n > 1:
if n % 2 and n % 3 and n % 5 and n % 7:
i = 3
while i * i < n + 1:
if not (n % i) :
break
i += 2
else:
r = True
elif n == 2 or n == 3 or n == 5 or n == 7:
r = True
return r
def jc(n):
r = 1
for i in range(n):
r *= (i + 1)
return r
for i in range(800 , 1201):
j , d = i , []
while j:
d . insert(0 , j % 10)
j //= 10
e = []
for k in range(len(d)):
e . append(jc(d[k]))
s = sum(e)
if prime(s):
t = "%d:%d!" % (i , d[0])
for k in range(1 , len(d)):
t += '+%d!' % d[k]
t += '=%d' % s
print(t)
运行时况D:\0002.Exercise\Python>python x.py
807:8!+0!+7!=45361
817:8!+1!+7!=45361
870:8!+7!+0!=45361
871:8!+7!+1!=45361
1002:1!+0!+0!+2!=5
1012:1!+0!+1!+2!=5
1020:1!+0!+2!+0!=5
1021:1!+0!+2!+1!=5
1102:1!+1!+0!+2!=5
1112:1!+1!+1!+2!=5
1120:1!+1!+2!+0!=5
1121:1!+1!+2!+1!=5
1200:1!+2!+0!+0!=5
D:\0002.Exercise\Python>
|