题意理解
这条题目就是用来验板子的
代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static class FastScanner {
private BufferedReader br;
private StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String nextToken() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.valueOf(nextToken());
}
}
public static void main(String[] args) {
FastScanner fs = new FastScanner();
long b = fs.nextLong();
long p = fs.nextLong();
long k = fs.nextLong();
System.out.println(b + "^" + p + " mod " + k + "=" + powMod(b, p, k));
}
static long powMod(long b, long p, long k) {
if(p == 0) {
return 1;
}
long res = powMod(b, p / 2, k);
res = res * res % k;
if(p % 2 == 1) {
res = res * b % k;
}
return res;
}
}