結果
問題 |
No.219 巨大数の概算
|
ユーザー |
![]() |
提出日時 | 2022-08-10 13:32:52 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,320 bytes |
コンパイル時間 | 5,603 ms |
コンパイル使用メモリ | 79,280 KB |
実行使用メモリ | 59,232 KB |
最終ジャッジ日時 | 2024-09-20 23:37:13 |
合計ジャッジ時間 | 23,778 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 WA * 50 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (n-- > 0) { sb.append(pow(new Num(sc.nextInt()), sc.nextInt())).append("\n"); } System.out.print(sb); } static Num pow(Num x, int p) { if (p == 0) { return new Num(1); } else if (p % 2 == 0) { return pow(x.pow(), p / 2); } else { return pow(x, p - 1).multiply(x); } } static class Num { long value; long p; public Num(long value, long p) { this.value = value; this.p = p; normalize(); } private void normalize() { while (value >= Integer.MAX_VALUE) { value /= 10; p++; } } public Num(long value) { this(value, 0); } public Num pow() { return new Num(value * value, p * 2); } public Num multiply(Num x) { return new Num(value * x.value, p + x.p); } public String toString() { long x = value; long y = p + 1; if (x < 10) { x *= 10; y--; } while (x >= 100) { x /= 10; y++; } return (x / 10) + " " + (x % 10) + " " + y; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }