← Complete problem index

PROJECT EULER · #0822

Square the Smallest

Statement only · SolvedOriginal problem ↗

A list initially contains the numbers 2,3,,n.
At each round, the smallest number in the list is replaced by its square. If there is more than one such number, then only one of them is replaced.

For example, below are the first three rounds for n=5: [2,3,4,5](1)[4,3,4,5](2)[4,9,4,5](3)[16,9,4,5].

Let S(n,m) be the sum of all numbers in the list after m rounds.

For example, S(5,3)=16+9+4+5=34. Also S(10,100)845339386(mod1234567891).

Find S(104,1016). Give your answer modulo 1234567891.

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.