Consider a code for Modular exponentiation assume we are calculating (x^n)% MOD
while(n>0)
{
if(n&1)
result = (result*x)%MOD;
cout<<result<<"\n";
x=(x*x)%MOD;
n=n>>1;
}
suppose x = 4 and n is large say 100 and MOD is 10^9 +6
so my program has overflow and giving result in -ve number
so in this program x can be very large < MOD
and when we multiply it be result intermediate value is very large so how to do it
p.s i am newbie :)