結果
問題 |
No.251 大きな桁の復習問題(1)
|
ユーザー |
![]() |
提出日時 | 2021-01-20 18:20:50 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 993 bytes |
コンパイル時間 | 3,131 ms |
コンパイル使用メモリ | 78,356 KB |
実行使用メモリ | 87,236 KB |
最終ジャッジ日時 | 2024-12-23 08:30:34 |
合計ジャッジ時間 | 71,243 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 11 |
ソースコード
import java.util.*; public class Main { static final int MOD = 129402307; public static void main (String[] args) { Scanner sc = new Scanner(System.in); long n = 0; for (char c : sc.next().toCharArray()) { n *= 10; n += c - '0'; n %= MOD; } ArrayList<Integer> m = new ArrayList<>(); for (char c : sc.next().toCharArray()) { m.add(c - '0'); } System.out.println(pow(n, m)); } static long pow(long x, ArrayList<Integer> p) { if (p.size() == 0) { return 1; } else if (p.get(p.size() - 1) % 2 == 0) { int y = 0; for (int i = 0; i < p.size(); i++) { y *= 10; int z = y + p.get(i); y = z % 2; z /= 2; p.set(i, z); } if (p.get(0) == 0) { p.remove(0); } return pow(x * x % MOD, p); } else { p.set(p.size() - 1, p.get(p.size() - 1) - 1); return pow(x, p) * x % MOD; } } }