-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler37.py
51 lines (43 loc) · 1003 Bytes
/
euler37.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
from math import sqrt
a=[0 for x in range(1000100)]
a[0]=a[1]=1
for i in range(2,int(sqrt(1000100))):
if a[i]==0:
j=i*i
while j<=1000000:
a[j]=1
j+=i
print 'primes are done'
for i in range(2,1000000):
if a[i]==0:
print i ,
sum=0
count=0
for i in range(11,1000000):
if a[i]==0:
#print i
temp=i
digitc=0
while temp>0:
digitc+=1
temp=temp/10
if a[temp]==0:
continue
else:
break
if temp==0:
temp=i
digitc-=1
while temp>0:
p=10**digitc
digitc-=1
temp=temp-(temp/p)*p
if a[temp]==0:
continue
else:
break
if temp==0:
count+=1
print '%d - %d' %(count,i)
sum+=i
print sum