#!/usr/bin/python
# encoding: utf-8
import time
import pprint
def allPrime(maxNum):
aList = range(0, maxNum)
def _do(aPrime):
for i in xrange(aPrime, maxNum, aPrime):
aList[i] = 0
return aPrime
return map(_do,
(i for i in xrange(2,maxNum) if aList[i])
)
t0 = time.time()
LIMIT = 1000000
primelist = allPrime(LIMIT)
primesets = set(primelist)
def loopshift(num):
numlst = list(str(num))
result = list()
for i in range(len(numlst)):
x = int(''.join(numlst[i:] + numlst[:i]))
if x not in primesets:
return None
result.append(x)
result = sorted(set(result))
for x in set(result):
primesets.remove(x)
return result
found = list()
for num in primelist:
xn = loopshift(num)
if xn and xn not in found:
found.append(xn)
pprint.pprint(found)在loopshift方法中对每个数据生成所有相关循环数,再判断每一个是否都是素数