-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpe60.py
74 lines (62 loc) · 1.32 KB
/
pe60.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#from itertools import combinations as com
def makeprime(x):
p=[2]
P=[2]
n=3
while n<x:
for i in p:
if n % i ==0:
break
else:
P.append(n)
while n > p[-1]**2:
p.append(P[len(p)])
n+=2
return P
########################################################################
def isprime(n):
if n<=1:
return False
t=n
for i in range(2,int(t**0.5)+1):
if t%i==0:
return False
return True
########################################################################
N=makeprime(100000)
N.remove(2)
N.remove(5)
########################################################################
def isit1(x,y):
t=int(str(x)+str(y))
if not isprime(t):
return False
t=int(str(y)+str(x))
if not isprime(t):
return False
return True
########################################################################
def isit(n,lis):
for i in lis:
if not isit1(n,i):
return False
return True
########################################################################
def main():
an=[[N[i]] for i in range(10)]
ans=an[:]
for i in range(10,len(N)):
for j in ans:
if isit(N[i],j):
#print j,
if len(j)==1:
ans.append([j[0],N[i]])
else:
j.append(N[i])
#print j
if len(j)==5:
print j,sum(j)
quit()
#print ans
########################################################################
main()