题目描述
输入 b,p,kb,p,k 的值,求 b^p \mod kbpmodk 的值。其中 2 \leq b,p,k \leq 10^92≤b,p,k≤109 。
输入描述
三个整数 b,p,kb,p,k。
输出描述
输出 b^p \mod k=sbpmodk=s,ss 为运算结果。
输入输出样例
示例
输入
2 10 9
输出
7
运行限制
- 最大运行时间:1s
- 最大运行内存: 128M
解法
import java.util.Scanner;
import java.math.BigInteger;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
long a = scan.nextLong();
long p1 = scan.nextLong();
long c = scan.nextLong();
BigInteger b= BigInteger.valueOf(a);
BigInteger p= BigInteger.valueOf(p1);
BigInteger k= BigInteger.valueOf(c);
BigInteger bigInteger = b.modPow(p, k);
System.out.println(bigInteger);
scan.close();
}
}