Description
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63).
Input
There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.
Output
For each testcase, output an integer, denotes the result of A^B mod C.
Sample Input
3 2 4 2 10 1000
Sample Output
1 24
解题思路:直接调用BigInteger大数类中的modPow(n,m)方法即可,java简单水过!
AC代码:
1 import java.util.Scanner; 2 import java.math.BigInteger; 3 public class Main { 4 public static void main(String[] args) { 5 Scanner scan = new Scanner(System.in); 6 while(scan.hasNext()){ 7 BigInteger a = scan.nextBigInteger(); 8 BigInteger b = scan.nextBigInteger(); 9 BigInteger c = scan.nextBigInteger(); 10 System.out.println(a.modPow(b,c));//大整数乘方和取模 11 } 12 } 13 }