Skip to content

Instantly share code, notes, and snippets.

@ssanin82
Created December 22, 2014 10:57
Show Gist options
  • Save ssanin82/56f1cadd7b010f82c7b3 to your computer and use it in GitHub Desktop.
Save ssanin82/56f1cadd7b010f82c7b3 to your computer and use it in GitHub Desktop.
typedef long long ULONG;
inline ULONG fastmodpow(ULONG a, ULONG b, ULONG x) {
ULONG res;
if (!b) {
res = 1;
} else if (1 == b) {
res = a;
} else {
res = fastmodpow(a, b / 2, x);
res = (res * res) % x;
if (b % 2) {
res = (res * a) % x;
}
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment