結果

問題 No.251 大きな桁の復習問題(1)
ユーザー GrenacheGrenache
提出日時 2015-07-25 12:00:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,014 bytes
コンパイル時間 7,577 ms
コンパイル使用メモリ 75,224 KB
実行使用メモリ 52,984 KB
最終ジャッジ日時 2023-09-23 04:48:44
合計ジャッジ時間 7,155 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
47,236 KB
testcase_01 WA -
testcase_02 AC 44 ms
49,348 KB
testcase_03 AC 45 ms
49,220 KB
testcase_04 AC 44 ms
49,264 KB
testcase_05 AC 44 ms
49,276 KB
testcase_06 AC 45 ms
49,244 KB
testcase_07 AC 45 ms
49,572 KB
testcase_08 AC 45 ms
49,236 KB
testcase_09 AC 99 ms
52,284 KB
testcase_10 AC 99 ms
51,436 KB
testcase_11 AC 99 ms
52,244 KB
testcase_12 AC 98 ms
52,556 KB
testcase_13 AC 95 ms
51,940 KB
testcase_14 AC 98 ms
52,204 KB
testcase_15 AC 97 ms
52,184 KB
testcase_16 AC 100 ms
51,892 KB
testcase_17 AC 99 ms
52,752 KB
testcase_18 AC 103 ms
52,984 KB
testcase_19 AC 92 ms
51,948 KB
testcase_20 AC 44 ms
49,324 KB
testcase_21 AC 44 ms
49,164 KB
testcase_22 AC 45 ms
49,376 KB
testcase_23 AC 46 ms
49,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder251_1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int MOD = 129402307;

        String n = sc.next();
        String m = sc.next();
        
        int nn = mod(n, MOD);

        if (nn == 0) {
        	System.out.println("0");
        } else {
        	int loop = mod(m, MOD - 1);
        	long x = nn;
        	long ret = 1;

        	while (loop > 0) {
        		if (loop % 2 == 1) {
        			ret = ret * x % MOD;
        		}
        		x = x * x % MOD;
        		loop /= 2;
        	}

        	System.out.println(ret);
        }

        sc.close();
    }
    
    private static int mod(String x, int MOD) {
    	char[] xx = x.toCharArray();
    	long ret = 0;
    	for (int i = 0; i < xx.length; i++) {
    		ret *= 10;
    		ret += xx[i] - '0';
    		ret %= MOD;
    	}

    	return (int)ret;
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;
		
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		
		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		
		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}
}
0