結果

問題 No.251 大きな桁の復習問題(1)
ユーザー tentententen
提出日時 2021-01-20 18:41:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 265 ms / 5,000 ms
コード長 833 bytes
コンパイル時間 4,253 ms
コンパイル使用メモリ 78,336 KB
実行使用メモリ 58,992 KB
最終ジャッジ日時 2023-08-24 22:43:14
合計ジャッジ時間 7,909 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
53,852 KB
testcase_01 AC 118 ms
55,668 KB
testcase_02 AC 118 ms
55,656 KB
testcase_03 AC 118 ms
55,976 KB
testcase_04 AC 116 ms
55,436 KB
testcase_05 AC 117 ms
55,732 KB
testcase_06 AC 117 ms
56,096 KB
testcase_07 AC 116 ms
53,980 KB
testcase_08 AC 116 ms
55,524 KB
testcase_09 AC 258 ms
58,648 KB
testcase_10 AC 265 ms
58,788 KB
testcase_11 AC 262 ms
58,508 KB
testcase_12 AC 253 ms
58,260 KB
testcase_13 AC 253 ms
58,700 KB
testcase_14 AC 252 ms
58,348 KB
testcase_15 AC 261 ms
58,300 KB
testcase_16 AC 254 ms
58,736 KB
testcase_17 AC 258 ms
58,748 KB
testcase_18 AC 250 ms
58,744 KB
testcase_19 AC 252 ms
58,992 KB
testcase_20 AC 117 ms
55,724 KB
testcase_21 AC 116 ms
55,296 KB
testcase_22 AC 115 ms
55,908 KB
testcase_23 AC 117 ms
55,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 129402307;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = 0;
		for (char c : sc.next().toCharArray()) {
		    n *= 10;
		    n += c - '0';
		    n %= MOD;
		}
		char[] arr = sc.next().toCharArray();
		int length = arr.length;
		long[] bases = new long[length];
		bases[length - 1] = n;
		long ans = pow(n, arr[length - 1] - '0');
		for (int i = length - 2; i >= 0; i--) {
		    bases[i] = pow(bases[i + 1], 10);
		    ans *= pow(bases[i], arr[i] - '0');
		    ans %= MOD;
		}
		System.out.println(ans);
	}
	
	static long pow(long x, long p) {
	    if (p == 0) {
	        return 1;
	    } else if (p % 2 == 0) {
	        return pow(x * x % MOD, p / 2);
	    } else {
	        return pow(x, p - 1) * x % MOD;
	    }
	}
}
0