Can anyone explain to me what's happening in line number 4, and how to understand these types of loops in future.
I was solving this problem. I have used basic approaches like pow(2,n) and (1<<n), but it overflows. Then I got this solution, but I'm unable to understand that fourth line. I know how to use for() loops in C++, but I'm a bit confused because of starting, i.e. nothing is there i.e. for(; e > 0; e >>= 1).
long long modpow(long long b, int e)
{
long long ans = 1;
for (; e > 0; e >>= 1)
{
if (e & 1)
ans = (ans * b) % mod;
b = (b * b) % mod;
}
return ans;
}