首页 > 代码库 > Problem 35:Circular primes

Problem 35:Circular primes

 

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