-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject_Euler_37.py
67 lines (41 loc) · 1.09 KB
/
Project_Euler_37.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
n=1000000
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]:
list.append(p)
SieveOfEratosthenes(n)
#print(list)
def truncable(k):
l=len(str(k))
for i in range(1,l):
k1=k%(10**i)
if k1 not in list:
return False
k2=k//(10**i)
if k2 not in list:
return False
return True
length=len(list)
c=0
sum=0
for i in range(4,length):
p=list[i]
if truncable(p):
print(p)
sum=sum+p
c=c+1
print()
print(sum)