Created
March 9, 2018 03:02
-
-
Save henrybear327/3fa6bbb76c2b0f52f91b8a6ebd9e7c40 to your computer and use it in GitHub Desktop.
simulation_x^y.c
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> | |
void solve() | |
{ | |
long long int x, y, p; | |
scanf("%lld %lld %lld", &x, &y, &p); | |
long long int ans = 1; | |
while (y > 0) { | |
if (y & 1) { | |
ans = ans * x % p; | |
} | |
y /= 2; | |
x = x * x % p; | |
} | |
printf("%lld\n", ans); | |
} | |
int main() | |
{ | |
int ncase; | |
scanf("%d", &ncase); | |
while (ncase--) | |
solve(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment