【杭电ACM】1097 A hard puzzle
【杭电ACM】1097 A hard puzzle
http://acm.hdu.edu.cn/showproblem.php?pid=1097先用int手写了算法结果竟然wrong answer,估计是测试数据很大,直接上BigInteger 和modPow(),轻松解决。
1 //author:pz 2 3 import java.math.BigInteger; 4 import java.util.Scanner; 5 6 public class Main{ 7 public static void main(String args[]){ 8 Scanner scan = new Scanner(System.in); 9 while(scan.hasNext()){ 10 BigInteger a = scan.nextBigInteger(); 11 BigInteger b = scan.nextBigInteger(); 12 BigInteger ans = a.modPow(b, new BigInteger("10")); 13 System.out.println(ans); 14 } 15 } 16 }