2017-08-23 17:57:34 +08:00

77 lines
1.4 KiB
Python

def isp(x, lis):
for i in lis:
if x % i == 0:
return False
if x < i ** 2:
break
return True
def makep(x):
p = [2]
P = [2]
n = 3
while len(P) < x:
for i in p:
if n % i == 0:
break
else:
P.append(n)
n += 2
while n > p[-1] ** 2:
p.append(P[len(p)])
return P
maxx = 1500
prime = makep(maxx)
prime.remove(2)
prime.remove(5)
#print len(prime)
dic = {}
for i in range(len(prime)):
if i % (maxx // 10) == 0:
print(i)
tmp = set([])
for j in range(i + 1, len(prime)):
aa = int(str(prime[i]) + str(prime[j]))
bb = int(str(prime[j]) + str(prime[i]))
if isp(aa, prime) and isp(bb, prime):
tmp.add(prime[j])
if len(tmp) > 0:
dic.update({prime[i]: tmp})
#print tmp
#else:
#print
print(len(dic.keys()))
out = []
for x1 in dic.keys():
for x2 in dic.get(x1):
if not x2 in dic.keys():
continue
both2 = dic.get(x1) & dic.get(x2)
if len(both2) == 0:
continue
else:
for x3 in both2:
if not x3 in dic.keys():
continue
both3 = both2 & dic.get(x3)
if len(both3) == 0:
continue
else:
for x4 in both3:
if not x4 in dic.keys():
continue
both4 = both3 & dic.get(x4)
if len(both4) == 0:
continue
else:
for x5 in both4:
out.append([x1, x2, x3, x4, x5])
print(sum(sorted(out)))