-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject_Euler_49.py
74 lines (50 loc) · 1.27 KB
/
Project_Euler_49.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
n=10000
list=[]
def SieveOfEratosthenes(n):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * 2, n+1, p):
prime[i] = False
p += 1
for p in range(2, n+1):
if prime[p] and p>=1000:
list.append(p)
SieveOfEratosthenes(n)
#print(list)
def digits(n):
d=[]
d.append(n%10)
n=n//10
d.append(n%10)
n=n//10
d.append(n%10)
n=n//10
d.append(n)
d.sort()
return d
#print(digits(6197))
final=[]
for p in list:
final.append(digits(p))
length=len(final)
#visited=[False for i in range(1061)]
for i in range(length):
k=final[i]
q=[]
q.append(list[i])
c=0
for j in range(i+1,length):
t=final[j]
if k==t:
c=c+1
q.append(list[j])
if c==2 and (q[0]+q[2]==q[1]+q[1]):
print(q)
#print(final)