Created
October 10, 2011 15:31
-
-
Save potix2/1275609 to your computer and use it in GitHub Desktop.
modpow
This file contains hidden or 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
//a^b mod m | |
long long modpow(long long a, long long b, long long m) { | |
long long ret = 1; | |
long long mul = a; | |
for ( ; b > 0; b = b >> 1) { | |
if ( b&1 ) { | |
ret = (ret * mul) % m; | |
} | |
mul = (mul * mul) % m; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment