結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,532 KB
testcase_01 WA -
testcase_02 AC 123 ms
55,576 KB
testcase_03 AC 120 ms
53,536 KB
testcase_04 AC 122 ms
55,592 KB
testcase_05 WA -
testcase_06 AC 123 ms
55,628 KB
testcase_07 AC 124 ms
55,544 KB
testcase_08 AC 123 ms
55,548 KB
testcase_09 AC 221 ms
56,656 KB
testcase_10 AC 223 ms
56,436 KB
testcase_11 AC 223 ms
56,352 KB
testcase_12 AC 221 ms
56,348 KB
testcase_13 AC 223 ms
56,584 KB
testcase_14 AC 223 ms
56,732 KB
testcase_15 AC 230 ms
56,108 KB
testcase_16 AC 212 ms
56,344 KB
testcase_17 AC 217 ms
56,788 KB
testcase_18 AC 223 ms
56,788 KB
testcase_19 AC 219 ms
56,292 KB
testcase_20 AC 121 ms
55,644 KB
testcase_21 AC 122 ms
55,864 KB
testcase_22 AC 120 ms
55,580 KB
testcase_23 AC 123 ms
55,348 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 && N_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 && M_is_zero){ System.out.println(1); }
		else if(N_mod == 0){ System.out.println(0); }
		else if(N_mod == 1){ System.out.println(1); }
		else{ System.out.println(mod_pow(N_mod, M_mod, MOD)); }
		
	}

}
0