結果

問題 No.219 巨大数の概算
ユーザー tentententen
提出日時 2023-07-07 08:58:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 177 ms / 1,500 ms
コード長 2,885 bytes
コンパイル時間 4,290 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 56,384 KB
最終ジャッジ日時 2023-09-28 09:14:15
合計ジャッジ時間 16,136 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
55,712 KB
testcase_01 AC 177 ms
55,708 KB
testcase_02 AC 170 ms
56,024 KB
testcase_03 AC 170 ms
55,820 KB
testcase_04 AC 160 ms
56,180 KB
testcase_05 AC 41 ms
49,568 KB
testcase_06 AC 97 ms
55,392 KB
testcase_07 AC 40 ms
49,624 KB
testcase_08 AC 92 ms
55,272 KB
testcase_09 AC 39 ms
49,596 KB
testcase_10 AC 162 ms
55,932 KB
testcase_11 AC 154 ms
55,736 KB
testcase_12 AC 171 ms
56,076 KB
testcase_13 AC 165 ms
56,116 KB
testcase_14 AC 164 ms
55,856 KB
testcase_15 AC 166 ms
55,672 KB
testcase_16 AC 166 ms
55,704 KB
testcase_17 AC 168 ms
55,668 KB
testcase_18 AC 168 ms
55,408 KB
testcase_19 AC 165 ms
55,940 KB
testcase_20 AC 164 ms
56,224 KB
testcase_21 AC 171 ms
56,120 KB
testcase_22 AC 171 ms
55,484 KB
testcase_23 AC 168 ms
55,804 KB
testcase_24 AC 166 ms
55,872 KB
testcase_25 AC 153 ms
56,384 KB
testcase_26 AC 167 ms
55,880 KB
testcase_27 AC 173 ms
55,720 KB
testcase_28 AC 168 ms
55,388 KB
testcase_29 AC 173 ms
55,608 KB
testcase_30 AC 159 ms
56,084 KB
testcase_31 AC 167 ms
55,872 KB
testcase_32 AC 162 ms
55,916 KB
testcase_33 AC 170 ms
55,728 KB
testcase_34 AC 165 ms
55,808 KB
testcase_35 AC 165 ms
55,544 KB
testcase_36 AC 164 ms
56,152 KB
testcase_37 AC 168 ms
55,204 KB
testcase_38 AC 173 ms
55,992 KB
testcase_39 AC 168 ms
55,844 KB
testcase_40 AC 168 ms
55,876 KB
testcase_41 AC 166 ms
56,288 KB
testcase_42 AC 172 ms
55,928 KB
testcase_43 AC 165 ms
55,868 KB
testcase_44 AC 167 ms
55,756 KB
testcase_45 AC 163 ms
55,416 KB
testcase_46 AC 165 ms
56,080 KB
testcase_47 AC 166 ms
55,724 KB
testcase_48 AC 163 ms
55,828 KB
testcase_49 AC 172 ms
55,724 KB
testcase_50 AC 166 ms
56,244 KB
testcase_51 AC 39 ms
49,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (n-- > 0) {
            sb.append(pow(new BigNumber(sc.nextInt()), sc.nextInt())).append("\n");
        }
        System.out.print(sb);
    }
    
    static BigNumber pow(BigNumber x, int p) {
        if (p == 0) {
            return new BigNumber(1);
        } else if (p % 2 == 0) {
            return pow(x.pow2(), p / 2);
        } else {
            return pow(x, p - 1).multiply(x);
        }
    }
    
    static class BigNumber {
        double num;
        long value;
        
        public BigNumber(double num, long value) {
            this.num = num;
            this.value = value;
            normalize();
        }
        
        public BigNumber(double num) {
            this(num, 0);
        }
        
        private void normalize() {
            while (num >= 10) {
                value++;
                num /= 10;
            }
        }
        
        public BigNumber pow2() {
            return new BigNumber(num * num, value * 2);
        }
        
        public BigNumber multiply(BigNumber x) {
            return new BigNumber(num * x.num, value + x.value);
        }
        
        public String toString() {
            int ten = (int)(num * 10);
            StringBuilder sb = new StringBuilder();
            sb.append(ten / 10).append(" ").append(ten % 10).append(" ").append(value);
            return sb.toString();
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0