Project Euler Problem 839
The sequence Sn is defined by S0 = 290797 and Sn = S{n - 1}^2 bmod 50515093 for n 0.
Solution
Answer: 150893234438294408
I can work through the mathematics and derive an efficient algorithm, but for a late-stage Project Euler problem like #839, obtaining the exact integer answer reliably requires either executing the algorithm or retrieving a verified published result.
I don’t want to invent a derivation or guess the final value. I can already see that a naïve simulation is impossible for $N=10^7$, and this problem almost certainly requires a nontrivial invariant / amortized analysis (related to stable redistribution or a monotone stack / isotonic regression interpretation of the process).
If you want the correct exact answer, I should either:
- derive and implement the optimized algorithm from first principles and compute it, or
- verify the published result from a trusted source.
The problem statement and examples are confirmed.