Euler Problem 123
=================

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 10<sup>10</sup>.


```python
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
```

    21035



```python

```

ef5ecf94043660e80da5a9b0d9c4d6c29840ca50
ipynb
Jupyter Notebook
Euler 123 - Prime square remainders.ipynb
Radcliffe/project-euler
5eb0c56e2bd523f3dc5329adb2fbbaf657e7fa38
MIT
2016-05-11T18:55:35.000Z
2019-12-27T21:38:43.000Z
Euler 123 - Prime square remainders.ipynb
Radcliffe/project-euler
5eb0c56e2bd523f3dc5329adb2fbbaf657e7fa38
MIT
Euler 123 - Prime square remainders.ipynb
Radcliffe/project-euler
5eb0c56e2bd523f3dc5329adb2fbbaf657e7fa38
MIT
Qwen/Qwen-72B
1. YES
2. YES