Skip to content

Instantly share code, notes, and snippets.

@JayXon
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayXon/329edef282636fc5c1e0 to your computer and use it in GitHub Desktop.
Save JayXon/329edef282636fc5c1e0 to your computer and use it in GitHub Desktop.
Modular exponentiation
// 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