結果

問題 No.251 大きな桁の復習問題(1)
ユーザー GrenacheGrenache
提出日時 2015-07-25 01:39:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 594 ms / 5,000 ms
コード長 1,998 bytes
コンパイル時間 3,692 ms
コンパイル使用メモリ 76,092 KB
実行使用メモリ 56,008 KB
最終ジャッジ日時 2023-08-22 16:59:08
合計ジャッジ時間 11,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,584 KB
testcase_01 AC 44 ms
49,692 KB
testcase_02 AC 44 ms
49,576 KB
testcase_03 AC 44 ms
49,608 KB
testcase_04 AC 44 ms
49,428 KB
testcase_05 AC 44 ms
49,512 KB
testcase_06 AC 44 ms
49,532 KB
testcase_07 AC 44 ms
49,560 KB
testcase_08 AC 45 ms
49,372 KB
testcase_09 AC 565 ms
55,948 KB
testcase_10 AC 594 ms
56,008 KB
testcase_11 AC 583 ms
55,764 KB
testcase_12 AC 545 ms
55,020 KB
testcase_13 AC 569 ms
55,868 KB
testcase_14 AC 582 ms
56,000 KB
testcase_15 AC 559 ms
55,760 KB
testcase_16 AC 593 ms
55,896 KB
testcase_17 AC 560 ms
55,560 KB
testcase_18 AC 570 ms
55,860 KB
testcase_19 AC 561 ms
55,152 KB
testcase_20 AC 45 ms
49,460 KB
testcase_21 AC 44 ms
49,552 KB
testcase_22 AC 45 ms
49,960 KB
testcase_23 AC 44 ms
49,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder251 {

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

        String n = sc.next();
        String m = sc.next();
        
        BigInteger nn = new BigInteger(n);
        nn = nn.mod(new BigInteger("129402307"));

		BigInteger loop = new BigInteger(m);
		long x = nn.longValue();
		long ret = 1;
		/*
		while (loop.compareTo(BigInteger.ZERO) > 0) {
			if (loop.mod(TWO).compareTo(BigInteger.ONE) == 0) {
				ret = ret * x % MOD;
			}
			x = x * x % MOD;
			loop = loop.divide(TWO);
		}
		*/
		
		int mm = loop.bitLength();
		for (int i = 0; i < mm; i++) {
			if (loop.testBit(i)) {
				ret = ret * x % MOD;
			}
			x = x * x % MOD;
		}

        System.out.println(ret);

        sc.close();
    }

	@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