fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int powMod2(int x, int y, int m){
  5. long long res = 1;
  6. while(y){
  7. if(y % 2 == 1){
  8. res *= x;
  9. res %= m;
  10. }
  11. x *= x;
  12. x %= m;
  13. y /= 2;
  14. }
  15. return res;
  16. }
  17.  
  18. int main(){
  19. int t;
  20. scanf("%d", &t);
  21. while(t--){
  22. int x, y, m;
  23. scanf("%d%d%d", &x, &y, &m);
  24. printf("%d\n", powMod2(x,y,m));
  25. }
  26. }
Success #stdin #stdout 0.01s 5520KB
stdin
2
2 2 4
5 2 4
stdout
0
1