project-euler/132_large_repunit_factors.py

33 lines
608 B
Python
Raw Normal View History

2023-03-26 17:21:44 +02:00
#!/usr/bin/env python3
def primes(n):
sieve = [True] * n
for p in range(2, int(n**0.5)):
if not sieve[p]:
continue
for i in range(p**2, n, p):
sieve[i] = False
return [i for i, p in enumerate(sieve) if p][2:]
target = 40
repw = 10**9
lim = 10**6
nums = primes(lim)
c = 0
s = 0
for p in nums[3:]:
if p%4 != 1 and p%5 != 1:
continue
if pow(10, repw, 9*p) == 1:
c += 1
s += p
#print c, p
if c == target:
break
if c < target:
print("Limit reached. Count = {}/{}".format(c, target))
print(s)