Posts

Showing posts from February, 2020

Pow with mod huge

llu modpow(llu base, llu exp, llu modulus) {   base %= modulus;   llu result = 1;   while (exp > 0) {     if (exp & 1) result = (result * base) % modulus;     base = (base * base) % modulus;     exp >>= 1;   }   return result; } int main() {     /*#ifndef ONLINE_JUDGE     freopen("input.txt", "r", stdin);     freopen("output.txt", "w", stdout);     #endif*/     fast     llu a,b=1000000000+7,c=2;     cin>>a;     cout<<modpow(c,a,b)<<endl; } https://stackoverflow.com/questions/8496182/calculating-powa-b-mod-n

Pow function for long data

llu pow1(llu x, llu y) {     llu temp;     if(y == 0)         return 1;     temp = pow1(x, y / 2);     if (y % 2 == 0)         return temp * temp;     else     {         if(y > 0)             return x * temp * temp;         else             return (temp * temp) / x;     } }