-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler35.py
40 lines (29 loc) · 828 Bytes
/
euler35.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
from math import ceil, log10
def isPrime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for x in range(3, int(n ** 0.5) + 1, 2):
if n % x == 0:
return False
return True
def circlesArePrime(num):
if num < 10:
return True
l = [num]
circle = num
while True:
# Suppose 197 is tested, then 7000 is added and whole divided by 10,
# yielding 719
circle = int(circle + (circle % 10) *
pow(10, ceil(log10(circle)))) / 10
if circle == num:
return True
if not isPrime(circle):
return False
limit = int(1e6)
print(len([z for z in (x for x in range(2, limit + 1)
if isPrime(x)) if circlesArePrime(z)]))