結果

問題 No.219 巨大数の概算
ユーザー tentententen
提出日時 2023-11-15 16:20:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 279 ms / 1,500 ms
コード長 2,762 bytes
コンパイル時間 3,519 ms
コンパイル使用メモリ 90,956 KB
実行使用メモリ 60,788 KB
最終ジャッジ日時 2023-11-15 16:20:45
合計ジャッジ時間 20,128 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
60,652 KB
testcase_01 AC 247 ms
60,304 KB
testcase_02 AC 279 ms
60,292 KB
testcase_03 AC 254 ms
60,284 KB
testcase_04 AC 246 ms
60,292 KB
testcase_05 AC 98 ms
57,064 KB
testcase_06 AC 149 ms
59,804 KB
testcase_07 AC 110 ms
56,756 KB
testcase_08 AC 161 ms
59,632 KB
testcase_09 AC 94 ms
57,064 KB
testcase_10 AC 245 ms
60,280 KB
testcase_11 AC 250 ms
60,788 KB
testcase_12 AC 243 ms
60,276 KB
testcase_13 AC 252 ms
60,268 KB
testcase_14 AC 249 ms
60,392 KB
testcase_15 AC 250 ms
60,524 KB
testcase_16 AC 255 ms
60,280 KB
testcase_17 AC 279 ms
60,428 KB
testcase_18 AC 258 ms
60,304 KB
testcase_19 AC 243 ms
60,536 KB
testcase_20 AC 252 ms
60,312 KB
testcase_21 AC 245 ms
60,424 KB
testcase_22 AC 254 ms
60,264 KB
testcase_23 AC 246 ms
60,356 KB
testcase_24 AC 250 ms
60,296 KB
testcase_25 AC 250 ms
60,656 KB
testcase_26 AC 256 ms
60,260 KB
testcase_27 AC 246 ms
60,272 KB
testcase_28 AC 247 ms
60,668 KB
testcase_29 AC 249 ms
60,664 KB
testcase_30 AC 253 ms
60,672 KB
testcase_31 AC 248 ms
60,524 KB
testcase_32 AC 255 ms
60,268 KB
testcase_33 AC 269 ms
60,672 KB
testcase_34 AC 254 ms
60,640 KB
testcase_35 AC 256 ms
60,280 KB
testcase_36 AC 249 ms
60,760 KB
testcase_37 AC 251 ms
60,168 KB
testcase_38 AC 257 ms
60,272 KB
testcase_39 AC 254 ms
60,280 KB
testcase_40 AC 248 ms
60,284 KB
testcase_41 AC 255 ms
60,548 KB
testcase_42 AC 260 ms
60,652 KB
testcase_43 AC 258 ms
60,308 KB
testcase_44 AC 250 ms
60,432 KB
testcase_45 AC 259 ms
60,292 KB
testcase_46 AC 243 ms
60,544 KB
testcase_47 AC 254 ms
58,760 KB
testcase_48 AC 252 ms
60,276 KB
testcase_49 AC 253 ms
60,272 KB
testcase_50 AC 254 ms
60,572 KB
testcase_51 AC 100 ms
56,932 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 Num(sc.nextInt()), sc.nextInt())).append("\n");
        }
        System.out.print(sb);
    }
    
    static Num pow(Num x, int p) {
        if (p == 0) {
            return new Num(1);
        } 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 size;
        
        public Num(double value, long size) {
            this.value = value;
            this.size = size;
            normalize();
        }
        
        public Num(double value) {
            this(value, 0);
        }
        
        private void normalize() {
            while (value >= 10) {
                value /= 10;
                size++;
            }
        }
        
        public Num pow2() {
            return new Num(value * value, size * 2);
        }
        
        public Num multiply(Num x) {
            return new Num(value * x.value, size + x.size);
        }
        
        public String toString() {
            int first = (int)(value);
            int second = (int)((value - first) * 10);
            return first + " " + second + " " + size;
        }
    }
}
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