Created
December 22, 2014 10:57
-
-
Save ssanin82/56f1cadd7b010f82c7b3 to your computer and use it in GitHub Desktop.
This file contains 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
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