結果

問題 No.219 巨大数の概算
ユーザー htensaihtensai
提出日時 2020-02-28 19:14:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 447 ms / 1,500 ms
コード長 1,909 bytes
コンパイル時間 3,739 ms
コンパイル使用メモリ 78,476 KB
実行使用メモリ 49,080 KB
最終ジャッジ日時 2024-04-21 17:41:17
合計ジャッジ時間 26,899 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 433 ms
49,064 KB
testcase_01 AC 412 ms
48,776 KB
testcase_02 AC 424 ms
47,856 KB
testcase_03 AC 416 ms
47,992 KB
testcase_04 AC 402 ms
48,636 KB
testcase_05 AC 118 ms
40,156 KB
testcase_06 AC 223 ms
45,632 KB
testcase_07 AC 115 ms
40,136 KB
testcase_08 AC 221 ms
45,668 KB
testcase_09 AC 133 ms
41,236 KB
testcase_10 AC 401 ms
48,660 KB
testcase_11 AC 398 ms
47,864 KB
testcase_12 AC 431 ms
47,752 KB
testcase_13 AC 430 ms
47,992 KB
testcase_14 AC 411 ms
48,176 KB
testcase_15 AC 431 ms
48,144 KB
testcase_16 AC 439 ms
47,896 KB
testcase_17 AC 435 ms
47,952 KB
testcase_18 AC 412 ms
48,516 KB
testcase_19 AC 435 ms
48,056 KB
testcase_20 AC 409 ms
48,112 KB
testcase_21 AC 425 ms
47,964 KB
testcase_22 AC 419 ms
48,608 KB
testcase_23 AC 410 ms
49,080 KB
testcase_24 AC 408 ms
48,672 KB
testcase_25 AC 418 ms
48,136 KB
testcase_26 AC 445 ms
48,060 KB
testcase_27 AC 420 ms
48,832 KB
testcase_28 AC 406 ms
48,860 KB
testcase_29 AC 428 ms
48,256 KB
testcase_30 AC 439 ms
47,880 KB
testcase_31 AC 443 ms
48,068 KB
testcase_32 AC 433 ms
48,288 KB
testcase_33 AC 441 ms
48,052 KB
testcase_34 AC 413 ms
48,288 KB
testcase_35 AC 432 ms
47,796 KB
testcase_36 AC 426 ms
47,836 KB
testcase_37 AC 430 ms
48,272 KB
testcase_38 AC 417 ms
48,200 KB
testcase_39 AC 419 ms
47,952 KB
testcase_40 AC 398 ms
48,496 KB
testcase_41 AC 426 ms
48,020 KB
testcase_42 AC 424 ms
48,036 KB
testcase_43 AC 444 ms
48,164 KB
testcase_44 AC 439 ms
48,080 KB
testcase_45 AC 429 ms
47,916 KB
testcase_46 AC 430 ms
48,292 KB
testcase_47 AC 447 ms
47,952 KB
testcase_48 AC 426 ms
48,116 KB
testcase_49 AC 411 ms
47,836 KB
testcase_50 AC 442 ms
48,152 KB
testcase_51 AC 128 ms
41,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
        }
    }
}
0