【杭电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 }

 

posted on 2013-04-17 00:30  P,Z  阅读(320)  评论(0编辑  收藏  举报