Last active
November 16, 2017 05:09
-
-
Save EsauPR/1ba9df13318f62cad067c046fa8c5fab 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
| #include <stdio.h> | |
| #define MOD 10000 | |
| int my_pow(int N, int P) { | |
| if (P == 0) return 1; | |
| if (P == 1) return (N % MOD); | |
| int temp_pow = my_pow(N, P/2); | |
| if ((P % 2) == 0) { | |
| return (temp_pow * temp_pow) % MOD; | |
| } | |
| return (((temp_pow * temp_pow) % MOD) * (N % MOD)) % MOD; | |
| } | |
| int main(int argc, char const *argv[]) { | |
| int N, P; | |
| scanf("%d %d", &N, &P); | |
| printf("%d\n", my_pow(N,P)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment