結果
問題 |
No.251 大きな桁の復習問題(1)
|
ユーザー |
|
提出日時 | 2015-07-25 12:00:59 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,014 bytes |
コンパイル時間 | 4,418 ms |
コンパイル使用メモリ | 78,080 KB |
実行使用メモリ | 51,956 KB |
最終ジャッジ日時 | 2024-07-16 04:51:49 |
合計ジャッジ時間 | 7,007 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 1 |
ソースコード
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(); } } } }