結果

問題 No.251 大きな桁の復習問題(1)
ユーザー tentententen
提出日時 2020-10-08 07:20:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 2,476 ms
コンパイル使用メモリ 71,848 KB
実行使用メモリ 58,256 KB
最終ジャッジ日時 2023-09-27 11:37:01
合計ジャッジ時間 7,616 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,016 KB
testcase_01 WA -
testcase_02 AC 109 ms
56,064 KB
testcase_03 AC 107 ms
55,644 KB
testcase_04 AC 113 ms
55,872 KB
testcase_05 AC 113 ms
55,440 KB
testcase_06 AC 111 ms
55,916 KB
testcase_07 AC 109 ms
55,888 KB
testcase_08 AC 113 ms
55,936 KB
testcase_09 AC 217 ms
56,548 KB
testcase_10 AC 202 ms
57,076 KB
testcase_11 AC 225 ms
56,404 KB
testcase_12 AC 209 ms
56,172 KB
testcase_13 AC 205 ms
56,544 KB
testcase_14 AC 202 ms
56,396 KB
testcase_15 AC 201 ms
54,796 KB
testcase_16 AC 213 ms
56,740 KB
testcase_17 AC 199 ms
57,112 KB
testcase_18 AC 193 ms
58,256 KB
testcase_19 AC 223 ms
56,008 KB
testcase_20 AC 107 ms
55,412 KB
testcase_21 AC 105 ms
55,708 KB
testcase_22 AC 114 ms
55,660 KB
testcase_23 AC 110 ms
55,424 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);
		char[] narr = sc.next().toCharArray();
		long n = 0;
		for (char c : narr) {
		    n *= 10;
		    n += c - '0';
		    n %= MOD;
		}
		if (n == 0) {
		    System.out.println(0);
		    return;
		}
		char[] marr = sc.next().toCharArray();
		long m = 0;
		for (char c : marr) {
		    m *= 10;
		    m += c - '0';
		    m %= MOD - 1;
		}
		System.out.println(pow(n, m));
	}
	
	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