-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_035.py
53 lines (41 loc) · 1016 Bytes
/
problem_035.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
class Prime:
primes = []
@staticmethod
def check_if_prime(n):
if Prime.primes[n]:
return True
else:
return False
@staticmethod
def get_primes_below_n(n=1000001):
"""
Seive of Eratosthenes
"""
from math import ceil
round_up = lambda n, prime: int(ceil(float(n)/prime))
primes = [True]*n
primes[0] = False
primes[1] = False
prime_list = []
for current_prime in range(2, n):
if not primes[current_prime]:
continue
prime_list.append(current_prime)
for multiplicant in range(2, round_up(n, current_prime)):
primes[current_prime * multiplicant] = False
Prime.primes = primes
return prime_list
def rotate(num):
lista = []
for i in range(len(str(num))):
lista.append(int(str(num)[i:] + str(num)[:i]))
return lista
primes_till_mil = Prime.get_primes_below_n()
print("Starting to count")
count = 0
for i in primes_till_mil:
rota = rotate(i)
if len(rota) == len(list(filter(Prime.check_if_prime, rota))):
print("Found", i)
count += 1
print(count)