結果
問題 |
No.219 巨大数の概算
|
ユーザー |
![]() |
提出日時 | 2020-01-18 17:42:31 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,916 bytes |
コンパイル時間 | 2,244 ms |
コンパイル使用メモリ | 77,268 KB |
実行使用メモリ | 63,672 KB |
最終ジャッジ日時 | 2024-06-27 22:04:27 |
合計ジャッジ時間 | 21,469 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 WA * 50 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] base = new int[31]; base[0] = 1; for (int i = 1; i < base.length; i++) { base[i] = base[i - 1] * 2; } StringBuilder sb = new StringBuilder(); for (int j = 0; j < n; j++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); int[] values = new int[32]; long[] counts = new long[32]; values[0] = a; for (int i = 0; i < 31; i++) { while (values[i] >= 100000) { values[i] /= 10; counts[i]++; } values[i + 1] = values[i] * values[i]; counts[i + 1] = counts[i] * 2; } int ans = 1; long size = 0; for (int i = 30; i >= 0; i--) { if (b >= base[i]) { ans *= values[i]; size += counts[i]; while (ans >= 100000) { ans /= 10; size++; } b -= base[i]; } } while (ans >= 100) { ans /= 10; size++; } int x; int y; if (ans < 10) { x = ans; y = 0; } else { x = ans / 10; y = ans % 10; size++; } sb.append(x).append(" ").append(y).append(" ").append(size).append("\n"); } System.out.print(sb); } }