結果

問題 No.251 大きな桁の復習問題(1)
ユーザー mits58mits58
提出日時 2016-07-25 19:50:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 705 ms / 5,000 ms
コード長 910 bytes
コンパイル時間 3,056 ms
コンパイル使用メモリ 73,740 KB
実行使用メモリ 59,124 KB
最終ジャッジ日時 2023-08-22 17:16:38
合計ジャッジ時間 13,665 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,560 KB
testcase_01 AC 118 ms
55,432 KB
testcase_02 AC 119 ms
55,904 KB
testcase_03 AC 118 ms
56,292 KB
testcase_04 AC 118 ms
54,432 KB
testcase_05 AC 119 ms
56,036 KB
testcase_06 AC 117 ms
55,928 KB
testcase_07 AC 118 ms
55,968 KB
testcase_08 AC 118 ms
56,076 KB
testcase_09 AC 693 ms
58,460 KB
testcase_10 AC 701 ms
59,124 KB
testcase_11 AC 695 ms
59,004 KB
testcase_12 AC 684 ms
58,820 KB
testcase_13 AC 699 ms
58,720 KB
testcase_14 AC 683 ms
58,776 KB
testcase_15 AC 687 ms
58,948 KB
testcase_16 AC 699 ms
58,424 KB
testcase_17 AC 689 ms
58,812 KB
testcase_18 AC 705 ms
58,420 KB
testcase_19 AC 697 ms
58,508 KB
testcase_20 AC 121 ms
55,800 KB
testcase_21 AC 118 ms
55,860 KB
testcase_22 AC 119 ms
56,044 KB
testcase_23 AC 118 ms
53,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()));
			}
		}
	}
}
0