blob: 5dd90497f3ab5a0fb440023e68bff1c138411248 (
plain)
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
|
import math
def rotate(n):
n = str(n)
m = ""
m+=n[len(n)-1]
for x in range(0,len(n)-1):
m+=n[x]
return int(m)
def isPrime(n):
for x in range(2,int(math.sqrt(n)+1)):
if n%x == 0: return False
return True
def nextPrime(n):
n-=1
while isPrime(n) == False:
n-=1
return n
def areRotationsPrime(n):
m = rotate(n)
if isPrime(n) == False: return False
while(m != n):
if isPrime(m) == False: return False
else: m = rotate(m)
return True
n, count = nextPrime(1000000), 0
while(n > 1):
if areRotationsPrime(n) == True:
count+=1
print(n)
n = nextPrime(n)
print("The Answer is:",count)
|