結果

問題 No.219 巨大数の概算
ユーザー tentententen
提出日時 2021-03-11 12:26:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 449 ms / 1,500 ms
コード長 1,417 bytes
コンパイル時間 3,374 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 48,428 KB
最終ジャッジ日時 2024-04-21 03:12:52
合計ジャッジ時間 27,841 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 436 ms
48,160 KB
testcase_01 AC 423 ms
47,764 KB
testcase_02 AC 424 ms
48,140 KB
testcase_03 AC 431 ms
48,280 KB
testcase_04 AC 432 ms
48,068 KB
testcase_05 AC 139 ms
41,328 KB
testcase_06 AC 226 ms
45,780 KB
testcase_07 AC 134 ms
41,416 KB
testcase_08 AC 235 ms
45,072 KB
testcase_09 AC 131 ms
41,140 KB
testcase_10 AC 441 ms
48,428 KB
testcase_11 AC 445 ms
48,120 KB
testcase_12 AC 422 ms
47,996 KB
testcase_13 AC 430 ms
48,060 KB
testcase_14 AC 431 ms
48,004 KB
testcase_15 AC 421 ms
48,224 KB
testcase_16 AC 423 ms
47,584 KB
testcase_17 AC 423 ms
47,844 KB
testcase_18 AC 431 ms
48,060 KB
testcase_19 AC 420 ms
48,044 KB
testcase_20 AC 422 ms
48,064 KB
testcase_21 AC 442 ms
48,000 KB
testcase_22 AC 430 ms
48,176 KB
testcase_23 AC 425 ms
48,216 KB
testcase_24 AC 431 ms
48,228 KB
testcase_25 AC 425 ms
48,140 KB
testcase_26 AC 429 ms
48,136 KB
testcase_27 AC 416 ms
47,748 KB
testcase_28 AC 423 ms
48,096 KB
testcase_29 AC 425 ms
48,120 KB
testcase_30 AC 423 ms
48,080 KB
testcase_31 AC 445 ms
47,908 KB
testcase_32 AC 449 ms
48,180 KB
testcase_33 AC 431 ms
48,348 KB
testcase_34 AC 413 ms
48,164 KB
testcase_35 AC 417 ms
47,856 KB
testcase_36 AC 400 ms
46,500 KB
testcase_37 AC 425 ms
48,060 KB
testcase_38 AC 420 ms
48,136 KB
testcase_39 AC 418 ms
48,108 KB
testcase_40 AC 447 ms
48,300 KB
testcase_41 AC 448 ms
48,072 KB
testcase_42 AC 420 ms
47,992 KB
testcase_43 AC 424 ms
47,860 KB
testcase_44 AC 405 ms
48,176 KB
testcase_45 AC 439 ms
48,084 KB
testcase_46 AC 437 ms
48,164 KB
testcase_47 AC 438 ms
48,280 KB
testcase_48 AC 431 ms
47,932 KB
testcase_49 AC 428 ms
48,004 KB
testcase_50 AC 427 ms
48,004 KB
testcase_51 AC 135 ms
41,464 KB
権限があれば一括ダウンロードができます

ソースコード

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