Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created March 9, 2018 03:02
Show Gist options
  • Save henrybear327/3fa6bbb76c2b0f52f91b8a6ebd9e7c40 to your computer and use it in GitHub Desktop.
Save henrybear327/3fa6bbb76c2b0f52f91b8a6ebd9e7c40 to your computer and use it in GitHub Desktop.
simulation_x^y.c
#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