Skip to content

Instantly share code, notes, and snippets.

@ssanin82
Created December 24, 2014 03:27
Show Gist options
  • Save ssanin82/e8397d2c54cf7759d5a8 to your computer and use it in GitHub Desktop.
Save ssanin82/e8397d2c54cf7759d5a8 to your computer and use it in GitHub Desktop.
typedef unsigned long long ULONG;
ULONG powm(ULONG a, ULONG n, ULONG mod) {
ULONG r = 1;
while (n) {
if (n & 1) {
r = (r * 1ll * a) % mod;
}
a = (a * 1ll * a) % mod;
n >>= 1;
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment