結果
| 問題 | No.251 大きな桁の復習問題(1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-07-25 01:39:06 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 594 ms / 5,000 ms | 
| コード長 | 1,998 bytes | 
| コンパイル時間 | 3,834 ms | 
| コンパイル使用メモリ | 78,924 KB | 
| 実行使用メモリ | 56,008 KB | 
| 最終ジャッジ日時 | 2024-12-17 17:21:49 | 
| 合計ジャッジ時間 | 11,706 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
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();
			}
		}
	}
}
            
            
            
        