project-euler/123_prime_square_remainders.py

21 lines
456 B
Python

#!/usr/bin/env python3
def main(m, lim=10**7):
for n, p in enumerate(primes(lim), 1):
r = ((2*n)%p)*p if n%2 else 2
if r > m:
return n, p, r
return False
def primes(n):
sieve = [True]*n
for p in range(2, len(sieve)):
if not sieve[p]:
continue
for i in range(2*p, len(sieve), p):
sieve[i] = False
yield p
#print(main(10**9, 10**6))
print(main(10**10, 10**6)[0])