码迷,mamicode.com
首页 > 其他好文 > 详细

Problem 35:Circular primes

时间:2015-01-09 06:58:19      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 

Circular primes

 

p = (lambda n,s=set():{‘2‘}|{str(i) for i in range(3,n,2) if ([j for j in range(i*3,n,i*2) if s.add(j)] or i not in s)})(int(1e6))

print(list(filter(lambda n:{‘‘.join([n[i-j] for i in range(len(n))]) for j in range(len(n))} < p, p)))

 

p = (lambda n,s=set():{2}|{str(i) for i in range(3,n,2) if ([j for j in range(i*3,n,i*2) if s.add(j)] or i not in s)})(int(1e6))

print(list(filter(lambda n:{‘‘.join([n[i-j] for i in range(len(n))]) for j in range(len(n))} < p, p)))

 

$S^2+\frac{1}{2}$

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 p = (lambda n,s=set():{2}|{str(i) for i in range(3,n,2) if ([j for j in range(i*3,n,i*2) if s.add(j)] or i not in s)})(int(1e6))
2 print(list(filter(lambda n:{‘‘.join([n[i-j] for i in range(len(n))]) for j in range(len(n))} < p, p)))
View Code

 

Problem 35:Circular primes

标签:

原文地址:http://www.cnblogs.com/ceares/p/4212314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!