由题意有理由猜测这些数都不大,猜测其上界,并检查该范围内的素数,稍加尝试即得这些素数是$23, 37, 53, 73, 313, 317, 373, 797, 3137, 3797, 739397$,它们的和是$748317$。
target=1000000
d=[0]*target
n=2
while n < target:
for i in range(n+n,target,n):
d[i]=d[i]+1
n=n+1
while n < target and d[n]>0:
n=n+1
primeList=[k for k in range(2,target) if d[k]==0]
primeSet=set(primeList)
i=4
res=[]
while i < len(primeList) and len(res) < 11:
p=primeList[i]
m=p/10
while m>0 and m in primeSet:
m/=10
d=10**(len(str(p))-1)
n=p%d
while d>1 and n in primeSet:
d/=10
n%=d
if m==0 and d==1:
res.append(p)
i=i+1
print res,sum(res)
|