結果

問題 No.219 巨大数の概算
ユーザー tentententen
提出日時 2021-03-11 12:26:11
言語 Java
(openjdk 23)
結果
AC  
実行時間 423 ms / 1,500 ms
コード長 1,417 bytes
コンパイル時間 5,915 ms
コンパイル使用メモリ 77,532 KB
実行使用メモリ 59,304 KB
最終ジャッジ日時 2024-10-13 01:34:01
合計ジャッジ時間 24,234 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	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(getAns(sc.nextInt(), sc.nextInt())).append("\n");
		}
		System.out.print(sb);
   }
   
   static String getAns(int x, int p) {
       return pow(new Num(x, 0), p).toString();
   }
   
   static Num pow(Num x, int p) {
       if (p == 0) {
           return new Num(1, 0);
       } else if (p % 2 == 0) {
           return pow(x.pow2(), p / 2);
       } else {
           return pow(x, p - 1).multiply(x);
       }
   }
   
   static class Num {
       double value;
       long base;
       
       public Num(double value, long base) {
           while (value >= 10) {
               base++;
               value /= 10;
           }
           this.value = value;
           this.base = base;
       }
       
       public Num pow2() {
           return new Num(value * value, base * 2);
       }
       
       public Num multiply(Num x) {
           return new Num(value * x.value, base + x.base);
       }
       
       public String toString() {
           int ans = (int)(value * 10);
           StringBuilder sb = new StringBuilder();
           sb.append(ans / 10).append(" ").append(ans % 10).append(" ").append(base);
           return sb.toString();
       }
   }
}

0