数字197可以被称为循环素数,因为197的三个数位循环移位后的数字:197,971,719均为素数。100以内这样的数字包括13个,2,3,5,7,11,13,17,31,37,71,73,79,97。要求任意正整数n以内一共有多少个这样的循环素数。
count = 0n = int(raw_input('n='))for i in range(2,n): bit = 0 mc = i while mc != 0: mc/=10 bit+=1 for j in range(2,i): if i%j == 0: break else: temp = 0 init = i while temp != init: flag = 0 many=i/10 single=i%10 temp=single*(10**(bit-1))+many for k in range(2,temp): if temp%k == 0: flag+=1 break else: i = temp if flag ==1: break if flag == 0: count+=1PRint count
新闻热点
疑难解答