Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 16, 2019 01:15
Show Gist options
  • Save surinoel/dd49cfc6f0866a45a1e47ce31f3fe1ed to your computer and use it in GitHub Desktop.
Save surinoel/dd49cfc6f0866a45a1e47ce31f3fe1ed to your computer and use it in GitHub Desktop.
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