Last active
December 25, 2015 03:59
-
-
Save sumanth232/d3247b576476de9c5580 to your computer and use it in GitHub Desktop.
a^b % mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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