-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem35.py
More file actions
28 lines (25 loc) · 747 Bytes
/
problem35.py
File metadata and controls
28 lines (25 loc) · 747 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
from itertools import compress
def findPrimes(n):
sieve = bytearray([True]) * (n//2+1)
for i in range(1,int(n**0.5)//2+1):
if sieve[i]:
sieve[2*i*(i+1)::2*i+1] = bytearray((n//2-2*i*(i+1))//(2*i+1)+1)
return [2,*compress(range(3,n,2), sieve[1:])]
primes = findPrimes(1000000)
circularPrimes = []
for prime in primes:
s = str(prime)
circular = True
# for every starting index
for i in range(len(s)):
num = ""
# for full rotation
for j in range(len(s)):
num += (s[(i+j) % len(s)])
num = int(num)
if not num in primes:
circular = False
break
if circular:
circularPrimes.append(prime)
print(len(circularPrimes))