projecteuler---->problem=35----Circular primes

Problem 35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?



import math
def isPrime(n):
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
def isCyclePrime(n):
    num = list()
    while n > 0:
        num.insert(0,n%10)
        n /= 10
    for i in range(len(num)):
        s = ''
        for k in range(i,len(num)):
            s += str(num[k])
        for j in range(i):
            s+=str(num[j])
        if isPrime(int(s)) == False:
            return False
    return True
def main():
    count =0
    for i in range(2,1000000):
        if isCyclePrime(i):
            count += 1
    print count
if __name__ == "__main__":
    main()


你可能感兴趣的:(python,projecteuler)