/** This functions returns b^e mod m
b --- base
e --- exponent
m --- mod
*/
int ModularExponentiation(int b, int e, int m)
{
int r = 1;
b %= m;
while(e)
{
if(e&1)
r=(r*b)%m;
b=(b*b)%m; // may overflow
e>>=1;
}
return r;
}
I am working on a system which has no Chinese input. Please don\'t blame me for typing English.