Euler 0035
The Problem:
FindCircular primes are primes that can be caesar'd and still be the sum ofprime all numbers equal to the sumway ofthrough.
Find factorials.how many circular primes there are below 1 million.
Considerations and Approach:
We canare findgoing to generate all the upperprimes limitunder 1000000, then iterate through all of them.
For each prime we will rotate it by fillingit's length - 1 and if every rotation is a numberprime, withthen 9s and checking that the sum of the digitsit is greatera thancircular the factorial of the number.
After we find the upper limit, we increment through it and check each ones factorial, then take the sum of the digits.prime
The Code:
import math
#find the upper limit
digitsprime_threshold = 91000000
sum_digitsnumber_list = math.factorial(9)list(range(2, whileprime_threshold+1))
sum_digits > digits:
digits *= 10
digits += 9
sum_digits += math.factorial(9)
print(len(str(digits)), digits, sum_digits)
### part 2 since we now know the upper limit
upper_limit = 2540160
fact_numsprime_list = []
current = 0
total_iteration = 0
while current < len(number_list):
if number_list[current] != -1:
prime = number_list[current]
prime_list += [prime]
increment = current + prime
while increment < len(number_list):
number_list[increment] = -1
increment += prime
total_iteration += 1
#print(number_list)
#print(prime_list)
current += 1
print(len(prime_list))
circ_primes = [2]
prime_list = [prime for prime in prime_list if '0' not in str(prime) and '2' not in str(prime) and '4' not in str(prime) and '6' not in str(prime) and '8' not in str(prime)]
print(len(prime_list))
iterations = 0
for prime in prime_list:
iterations += 1
circular = True
current = prime
for i in range(3,1,int(math.log(prime, upper_limit)10))+1):
current = int(str(current)[-1] + str(current)[0:-1])
#print(prime, current)
#print(prime, current)
if icurrent == sum([math.factorial(int(x)) for xnot in str(i)]):prime_list:
fact_numscircular = False
break
if circular:
circ_primes += [i]prime]
if iterations % 10000 == 0:
print(fact_nums)iterations/len(prime_list))
#print(circ_primes)
print(len(circ_primes))