結果
| 問題 |
No.219 巨大数の概算
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-02-28 19:14:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 412 ms / 1,500 ms |
| コード長 | 1,909 bytes |
| コンパイル時間 | 2,604 ms |
| コンパイル使用メモリ | 78,140 KB |
| 実行使用メモリ | 48,912 KB |
| 最終ジャッジ日時 | 2024-10-13 16:32:35 |
| 合計ジャッジ時間 | 24,266 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 51 |
ソースコード
import java.util.*;
public class Main {
static final int MOD = 1000000007;
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(calc(sc.nextInt(), sc.nextInt())).append("\n");
}
System.out.print(sb);
}
static String calc(double a, int b) {
BigNumber org = new BigNumber(a);
int[] base = new int[31];
BigNumber[] arr = new BigNumber[31];
base[0] = 1;
arr[0] = org;
for (int i = 1; i < 31; i++) {
base[i] = base[i - 1] * 2;
arr[i] = arr[i - 1].pow();
}
BigNumber ans = new BigNumber(1.0);
for (int i = 30; i >= 0; i--) {
if (b >= base[i]) {
ans = ans.mul(arr[i]);
b -= base[i];
}
}
int x = (int)(ans.x);
int y = (int)(ans.x * 10) % 10;
StringBuilder sb = new StringBuilder();
return sb.append(x).append(" ").append(y).append(" ").append(ans.count).toString();
}
static class BigNumber {
double x;
long count;
public BigNumber(double a) {
x = a;
while (x >= 10) {
x /= 10;
count++;
}
}
public BigNumber(double x, long count) {
this.x = x;
this.count = count;
}
public BigNumber pow() {
double y = x * x;
long next = count * 2;
while (y >= 10) {
y /= 10;
next++;
}
return new BigNumber(y, next);
}
public BigNumber mul(BigNumber another) {
double y = x * another.x;
long next = count + another.count;
while (y >= 10) {
y /= 10;
next++;
}
return new BigNumber(y, next);
}
}
}
htensai