fork download
  1. import java.io.Console;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5. static long rozloz(long b,long x,long n){
  6.  
  7. int i;
  8. long result = 1;
  9. for(i=0;b!=0;i++){
  10. if(b % 2 != 0){
  11. result*=x;
  12. result = result % n;
  13. }
  14. x = x * x;
  15. x = x % n;
  16. b = b/2;
  17. }
  18. return result;
  19. }
  20.  
  21. public static void main(String[] args) {
  22.  
  23. Scanner input = new Scanner(System.in);
  24.  
  25. //
  26. long n, x, t, b, j;
  27.  
  28. t = input.nextLong();
  29. j=0;
  30. while(j<t){
  31. //scanf("%d %d %d",&x,&b,&n);
  32. x = input.nextLong();
  33. b = input.nextLong();
  34. n = input.nextLong();
  35. x=x%n;
  36. //printf("%d\n",rozloz(b,x,n));
  37. System.out.println(rozloz(b,x,n));
  38. j++;
  39. }
  40.  
  41. }
  42.  
  43. }
Success #stdin #stdout 0.07s 213312KB
stdin
5 
1 0 13
2 4 13
3 2 4
2 7 10
81 9345 75
stdout
1
3
1
8
51