AcWing 89. a^b(Java 快速幂模板)
原题链接
简单
作者:
Limited
,
2021-03-06 22:19:15
,
所有人可见
,
阅读 271
import java.util.*;
import java.lang.*;
public class Main {
static Scanner scanner = new Scanner(System.in);
static long fastPower(long a, long b, long p) {
long res = 1L;
while (b > 0) {
if ((b & 1) == 1) res = res * a % p;
b >>= 1;
a = a * a % p;
}
return res % p;
}
public static void main(String[] args) {
long a = scanner.nextLong(), b = scanner.nextLong(), p = scanner.nextLong();
System.out.println(fastPower(a, b, p));
}
}