一共有
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
while (in.hasNextInt()) {
// 注意,用例中的数较大,用int会溢出
long a = in.nextInt();
long b = in.nextInt();
long p = in.nextInt();
System.out.println(quickPow(a,b,p));
}
}
// 非递归
public static long quickPow(long num, long pow, long p) {
long result = 1l;
while (pow > 0) {
if((pow&1)>0){
result = (result*num) % p;
}
pow >>= 1;
num = (num*num) % p;
}
return result % p;
}
}