Project-Euler-700 Eulercoin
$$
EulerCoin_n = (1504170715041707 * n) mod (4503599627370517)
$$
We can see finally the $ EulerCoin_n $ will become 1 and then the $n$ should be $3451657199285664$, the reason is below:
From $pow(1504170715041707,-1,4503599627370517) = 3451657199285664$,
so we have $1504170715041707 * 3451657199285664 \ mod \ 4503599627370517 = 1$
Now we know the upper limit of $n$ is $3451657199285664$, that is still too big. Hmm, it will cost us 1 year to calculate the result.
If we go straight, we can get the first 15 results of $n$ and $EulerCoin$ very easily:
1 | n = 3, EulerCoin_n = 8912517754604 |
We find then the upper limit of $EulerCoin_n$ is only $15806432$. If we go reverse direction, we know $EulerCoin_n$, could we get the corresponding value of $n$ and check if $n$ is decreasing? The answer is we can:
$$EulerCoin_n = (1504170715041707 * n) mod (4503599627370517) $$
$$ => (EulerCoin_n * 3451657199285664) mod 4503599627370517 = n$$
1 | before = 3451657199285664 |
Plus the first 15 results of $EulerCoin_n$, we can get the final sum.