-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_035.py
More file actions
37 lines (29 loc) · 819 Bytes
/
Problem_035.py
File metadata and controls
37 lines (29 loc) · 819 Bytes
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
import math
# Get primes up to a specified number
def get_primes_up_to(num):
prime_numbers = set()
checker = []
for i in range(0, num):
checker.append(True)
for i in range(2, int(math.sqrt(num))+1):
if checker[i]:
counter = 2
while i * counter < num:
checker[i * counter] = False
counter += 1
for i in range(2, num):
if checker[i]:
prime_numbers.add(i)
return prime_numbers
primes = get_primes_up_to(1000000)
count = 0
for num in primes:
check = True
for i in range(1, len(str(num))):
new_number = int(f"{str(num)[-(len(str(num)) - i):]}{str(num)[:i]}")
if new_number not in primes:
check = False
break
if check:
count +=1
print(count)