# coding=UTF-8
print "Q34:\n"
'''
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?
'''
#范围[1, 100-0000]
'''
算法
1.首先生成一百万内的素数
使用map存一百万内的素数,key=素数值,value:0(重复),1(非重复)
2.for prime in map
list_prime_rotation = get_list_rotation(prime)
for x in list_prime_rotation
if x not in map
delete x from map
found = false
if found == false
delete prime from map
'''
import tools
'''
ratation算法
1,2/2,3 917 971
2,3/3,1 179 917
3,1/1,2 719 179
rotate(list,pos1,pos2)
x = list[pos1]
list[pos1] = list[pos2]
list[pos2] = x
index from 1 to len - 1
step from 1 to len - 1
rotate(index%(len+1),(index+1)%(len+1)+1)
index = index + 1
if index == len + 1
index = 1
'''
def get_list_rotation(number):
list_res = []
list_digits = tools.int_to_list_digits_simple_but_not_fast(number)
list_container = list_digits[:]
l = len(list_digits)
for i in range(0,l-1):
j = i
for step in range(0,l-1):
pos1 = j%l
pos2 = (j+1)%l
x = list_digits[pos1]
list_digits[pos1] = list_digits[pos2]
list_digits[pos2] = x
j = j + 1
if j == l:
j = 0
list_res.append(int(''.join(map(str,list_digits))))
return list_res
print get_list_rotation(197)
#print get_list_rotation(19)
7461

被折叠的 条评论
为什么被折叠?



