-
Notifications
You must be signed in to change notification settings - Fork 10
/
pe037.py
47 lines (40 loc) · 906 Bytes
/
pe037.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
#code created by NamanNimmo Gera
#11:29am, April 14, 2019.
def isPrime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def checkLeft(n):
num = n
while(num>0):
if isPrime(num):
num = num // 10
else:
return False
return True
def checkRight(n):
a = str(n)
for i in range(1,len(a)):
if isPrime(int(a[i:])):
continue
else:
return False
return True
tot=0
prime_list = []
for i in range(11, 1000000):
if isPrime(i):
prime_list.append(i)
for j in prime_list:
if checkRight(j) and checkLeft(j):
tot = tot + j
print(tot)