結果

問題 No.251 大きな桁の復習問題(1)
ユーザー uafr_csuafr_cs
提出日時 2015-09-13 18:58:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 78,124 KB
実行使用メモリ 57,184 KB
最終ジャッジ日時 2023-09-26 11:47:06
合計ジャッジ時間 7,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,624 KB
testcase_01 WA -
testcase_02 AC 120 ms
55,628 KB
testcase_03 AC 116 ms
55,940 KB
testcase_04 AC 120 ms
55,628 KB
testcase_05 AC 119 ms
55,624 KB
testcase_06 AC 117 ms
55,724 KB
testcase_07 AC 117 ms
56,032 KB
testcase_08 AC 120 ms
55,356 KB
testcase_09 AC 215 ms
56,352 KB
testcase_10 AC 214 ms
56,332 KB
testcase_11 AC 207 ms
56,356 KB
testcase_12 AC 214 ms
56,436 KB
testcase_13 AC 216 ms
56,416 KB
testcase_14 AC 218 ms
56,112 KB
testcase_15 AC 211 ms
56,732 KB
testcase_16 AC 220 ms
56,432 KB
testcase_17 AC 220 ms
56,176 KB
testcase_18 AC 203 ms
57,184 KB
testcase_19 AC 219 ms
56,352 KB
testcase_20 AC 119 ms
55,804 KB
testcase_21 AC 119 ms
55,856 KB
testcase_22 AC 119 ms
55,600 KB
testcase_23 AC 119 ms
56,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static long mod_pow(long n, long m, long MOD){
		if(m == 0){ return 1; }
		if(m == 1){ return n % MOD; }
		if(m % 2 != 0){
			return (mod_pow(n, m - 1, MOD) * n) % MOD; 
		}else{
			final long ret = mod_pow(n, m / 2, MOD);
			
			return (ret * ret) % MOD;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long MOD = 129402307;
		
		char[] N_ch = sc.next().toCharArray();
		final boolean N_is_zero = N_ch.length == 1 && N_ch[0] == '0';
		char[] M_ch = sc.next().toCharArray();
		final boolean M_is_zero = M_ch.length == 1 && M_ch[0] == '0';
		
		long N_mod = 0, M_mod = 0;
		for(final char c : N_ch){
			N_mod *= 10;
			N_mod += Character.getNumericValue(c);
			N_mod %= MOD;
		}
		for(final char c : M_ch){
			M_mod *= 10;
			M_mod += Character.getNumericValue(c);
			M_mod %= (MOD - 1);
		}
		//System.out.println(N_mod + " " + M_mod);
		
		if(N_mod == 0){ System.out.println(0); }
		else{ System.out.println(mod_pow(N_mod, M_mod, MOD)); }
		
	}

}
0