Let pn be the nth prime: 2, 3, 5, 7, 11, ..., and let r be the remainder when $(p_n-1)^n + (p_n+1)^n$ is divided by $p_n^2$.
For example, when n = 3, p3 = 5, and 43 + 63 = 280 ≡ 5 mod 25.
The least value of n for which the remainder first exceeds 109 is 7037.
Find the least value of n for which the remainder first exceeds 1010.
In [1]:
from sympy import sieve
primes = list(sieve.primerange(1, 500000))[0::2]
for k, p in enumerate(primes):
n = 2*k + 1
remainder = (2*n*p) % (p*p)
if remainder > 10**10:
print(n)
break
In [ ]: