blob: d832c4ff53a3385a23d6e4778c5fbf73a24764fb (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import math
arrCirPrime = []
def IsPrime(nInput):
for nDiv in range(2, int(math.sqrt(nInput)) + 1):
if nInput % nDiv == 0:
return False
return True
def IsCircularPrime(nNum):
if not IsPrime(nNum):
return False
strNum = str(nNum)
nLen = len(strNum)
for nSubLoop in range(0, nLen):
strNum = strNum[1:] + strNum[0]
nVal = int(strNum)
if not IsPrime(nVal):
return False
nExistCount = arrCirPrime.count(nVal)
if nExistCount > 0:
return False
arrCirPrime.append(nNum)
return True
nCount = 0
nLoop = 101
while nCount < 10:
if IsCircularPrime(nLoop):
print (str(nLoop))
nCount = nCount + 1
nLoop = nLoop + 1
|