結果
| 問題 | No.251 大きな桁の復習問題(1) | 
| コンテスト | |
| ユーザー |  mits58 | 
| 提出日時 | 2016-07-25 19:50:33 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 729 ms / 5,000 ms | 
| コード長 | 910 bytes | 
| コンパイル時間 | 2,557 ms | 
| コンパイル使用メモリ | 77,792 KB | 
| 実行使用メモリ | 57,448 KB | 
| 最終ジャッジ日時 | 2024-12-17 17:39:45 | 
| 合計ジャッジ時間 | 12,904 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
	static BigInteger mod=BigInteger.valueOf(129402307);
	static long pow(long a,long x,long m){
		if(x==0) return 1;
		else if(x%2==0) return pow((a*a)%m,x/2,m)%m;
		else return (a*pow((a*a)%m,x/2,m))%m;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			BigInteger n=sc.nextBigInteger();
			BigInteger m=sc.nextBigInteger();
			if(n.compareTo(BigInteger.ZERO)==0) System.out.println(0);
			else if(m.compareTo(BigInteger.ZERO)==0) System.out.println(1);
			else{
				n=n.remainder(mod);
				m=m.remainder(mod.subtract(BigInteger.ONE));
				long nn=n.longValue(),mm=m.longValue();
				if(mm==0 && nn==0) System.out.println(0);
				else if(mm==0) System.out.println(1);
				else if(nn==0) System.out.println(0);
				else System.out.println(pow(nn,mm,mod.longValue()));
			}
		}
	}
}
            
            
            
        