Last active
August 29, 2015 14:13
-
-
Save JayXon/329edef282636fc5c1e0 to your computer and use it in GitHub Desktop.
Modular exponentiation
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
// return (b ^ e) % m | |
uint64_t modexp(uint64_t b, uint64_t e, uint64_t m = 1000000007) { | |
uint64_t r = 1; | |
while (e) { | |
if (e & 1) | |
r = (r * b) % m; | |
b = (b * b) % m; | |
e >>= 1; | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment