Last active
July 16, 2019 01:15
-
-
Save surinoel/dd49cfc6f0866a45a1e47ce31f3fe1ed to your computer and use it in GitHub Desktop.
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
long long go(int a, int b, int c) { | |
if (b == 0) { | |
return 1; | |
} | |
else if (b == 1) { | |
return a % c; | |
} | |
long long tmp = go(a, b / 2, c) % c; | |
long long ans = ((tmp % c) * (tmp % c)) % c; | |
if (b % 2 == 0) { | |
return ans; | |
} | |
else { | |
return (a * ans) % c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment