AcWing 89. JAVA-大整形便捷易懂
原题链接
简单
作者:
crayon不小心
,
2021-02-04 13:55:18
,
所有人可见
,
阅读 313
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a = sc.nextBigInteger();
BigInteger b = sc.nextBigInteger();
BigInteger p = sc.nextBigInteger();
BigInteger res = BigInteger.ONE.mod(p);
while (b.compareTo(BigInteger.ZERO) > 0)
{
if (b.and(BigInteger.ONE).intValue()>0) res = res .multiply(a).mod(p);
a = a.multiply(a).mod(p);
b = b.shiftRight(1);
}
System.out.println(res);
}
}