Skip to content

Instantly share code, notes, and snippets.

@sumanth232
Last active December 25, 2015 03:59
Show Gist options
  • Save sumanth232/d3247b576476de9c5580 to your computer and use it in GitHub Desktop.
Save sumanth232/d3247b576476de9c5580 to your computer and use it in GitHub Desktop.
a^b % mod
#define mod 1000000007LL
typedef long long ll;
ll power(ll a, ll b)
{
ll result = 1;
while (b){
if (b&1){ // if(b%2 == 1)
result = ((result % mod) * (a % mod)) % mod;
}
b >>=1 ; // b = b/2
a = (a*a) % mod;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment