結果

問題 No.251 大きな桁の復習問題(1)
ユーザー tentententen
提出日時 2021-01-20 18:20:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 993 bytes
コンパイル時間 3,987 ms
コンパイル使用メモリ 75,472 KB
実行使用メモリ 55,920 KB
最終ジャッジ日時 2023-08-24 22:13:15
合計ジャッジ時間 12,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,908 KB
testcase_01 AC 114 ms
55,672 KB
testcase_02 AC 118 ms
55,884 KB
testcase_03 AC 117 ms
55,900 KB
testcase_04 AC 118 ms
55,472 KB
testcase_05 AC 114 ms
55,920 KB
testcase_06 AC 115 ms
55,596 KB
testcase_07 AC 115 ms
55,600 KB
testcase_08 AC 115 ms
55,892 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
		}
		ArrayList<Integer> m = new ArrayList<>();
		for (char c : sc.next().toCharArray()) {
		    m.add(c - '0');
		}
		System.out.println(pow(n, m));
	}
	
	static long pow(long x, ArrayList<Integer> p) {
	    if (p.size() == 0) {
	        return 1;
	    } else if (p.get(p.size() - 1) % 2 == 0) {
	        int y = 0;
	        for (int i = 0; i < p.size(); i++) {
	            y *= 10;
	            int z = y + p.get(i);
	            y = z % 2;
	            z /= 2;
	            p.set(i, z);
	        }
	        if (p.get(0) == 0) {
	            p.remove(0);
	        }
	        return pow(x * x % MOD, p);
	    } else {
	        p.set(p.size() - 1, p.get(p.size() - 1) - 1);
	        return pow(x, p) * x % MOD;
	    }
	}
}
0