Easy Money problem from HackerEarth Collegiate Cup Second Elimination round simplified to compute (2^(2^n))-1 with modulus 1e9+7.
To compute (2^(2^n))%mod, where mod = 1e9+7 and 1≤ n ≤10^18
author solution:
ans = power(2, n, mod -1)
ans = power(2, ans, mod)
Can someone please explain why mod -1 is taken ?
This is because by Fermat's Little Theorem, ap - 1 ≡ 1(modp). Thus, we reduce the exponent modulo p - 1 = 109 + 6.
I added a detailed explanation describing how to do it in the UPDATE section of the editorial, please take a look: https://www.hackerearth.com/hackerearth-collegiate-cup-second-elimination/algorithm/easy-money/editorial/
Please also post the editorial for the problem Shooting Range, the present editorial just has the code which is not quite helpful. Thank you :)
It will be posted tomorrow. I'll reply to your comment when it's available. If you are interested, I just posted the editorial to Computer Virus problem.
Hi, I just want to let you know that I've just posted editorial to Shooting Range problem — you can take a look now.
Keeping up with your word thanks a lot man :)