Circular Primes

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?

To solve this problem involves both mathematics and programming, because checking for prime in simple mathematical methods and checking for circular primes below one million manually will be very tiresome and time-consuming. Here is one way to solve the problem using Python:

“`python
import itertools

def is_prime(n):
if n < 2: return False if n == 2: return True if not n & 1: return False for x in range(3, int(n**0.5)+1, 2): if n % x == 0: return False return True def rotations(n): for p in range(len(n)): yield int(n[p:] + n[:p]) def is_circular_prime(n): str_n = str(n) if("0" in str_n or "2" in str_n or "4" in str_n or "5" in str_n or "6" in str_n or "8" in str_n): return False return all(is_prime(int(r)) for r in rotations(str(n))) circular_primes = [n for n in range(2, 1000000) if is_circular_prime(n)] print(len(circular_primes)) ``` In this code, `is_prime(n)` checks whether a number `n` is prime or not. The `rotations(n)` function creates a generator for all possible rotations of the number `n`. `is_circular_prime(n)` checks whether the number `n` is a circular prime or not; it first checks if `n` includes any even digit or 5, as we know that any number having an even number or 5 in it can't be prime except the numbers 2 and 5 itself. Then using `all()` function, it checks that all rotations are prime. If all rotations are prime, then `n` is circular prime. Finally, it uses list comprehension to generate a list of all circular primes below one million and then uses `len()` to count how many there are. Running the code shows there are 55 circular primes below one million.

More Answers:
Pandigital Products
Digit Cancelling Fractions
Digit Factorials

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts