結果

問題 No.2420 Simple Problem
ユーザー tentententen
提出日時 2023-08-17 10:32:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 759 ms / 2,000 ms
コード長 2,259 bytes
コンパイル時間 2,902 ms
コンパイル使用メモリ 84,964 KB
実行使用メモリ 62,356 KB
最終ジャッジ日時 2024-05-04 17:21:15
合計ジャッジ時間 31,027 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
37,128 KB
testcase_01 AC 515 ms
58,104 KB
testcase_02 AC 92 ms
38,268 KB
testcase_03 AC 292 ms
52,524 KB
testcase_04 AC 710 ms
62,304 KB
testcase_05 AC 564 ms
59,288 KB
testcase_06 AC 759 ms
61,992 KB
testcase_07 AC 739 ms
62,160 KB
testcase_08 AC 731 ms
61,748 KB
testcase_09 AC 718 ms
61,972 KB
testcase_10 AC 753 ms
61,468 KB
testcase_11 AC 717 ms
61,816 KB
testcase_12 AC 736 ms
61,924 KB
testcase_13 AC 723 ms
61,664 KB
testcase_14 AC 740 ms
62,356 KB
testcase_15 AC 711 ms
62,204 KB
testcase_16 AC 732 ms
61,820 KB
testcase_17 AC 724 ms
61,784 KB
testcase_18 AC 758 ms
61,776 KB
testcase_19 AC 734 ms
61,896 KB
testcase_20 AC 743 ms
61,736 KB
testcase_21 AC 753 ms
61,960 KB
testcase_22 AC 736 ms
61,412 KB
testcase_23 AC 720 ms
61,856 KB
testcase_24 AC 723 ms
61,724 KB
testcase_25 AC 721 ms
61,588 KB
testcase_26 AC 46 ms
36,892 KB
testcase_27 AC 684 ms
59,428 KB
testcase_28 AC 719 ms
59,424 KB
testcase_29 AC 699 ms
59,896 KB
testcase_30 AC 694 ms
59,800 KB
testcase_31 AC 689 ms
59,652 KB
testcase_32 AC 46 ms
36,684 KB
testcase_33 AC 547 ms
58,228 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) {
            long a = sc.nextInt();
            long b = sc.nextInt();
            long target = a * b * 4;
            long left = 0;
            long right = Integer.MAX_VALUE / 2;
            while (right - left > 1) {
                long m = (left + right) / 2;
                long p = m * m - a - b;
                if (p < 0 || pow2(p) <= target) {
                    left = m;
                } else {
                    right = m;
                }
            }
            sb.append(right).append("\n");
        }
        System.out.print(sb);
    }
    
    static long pow2(long x) {
        if (x != 0 && Long.MAX_VALUE / x <= x) {
            return Long.MAX_VALUE;
        } else {
            return x * x;
        }
    }
    
}
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