結果

問題 No.816 Beautiful tuples
ユーザー tentententen
提出日時 2020-11-18 13:54:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 698 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 70,912 KB
実行使用メモリ 57,852 KB
最終ジャッジ日時 2023-09-30 15:01:06
合計ジャッジ時間 5,053 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 119 ms
55,992 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 120 ms
55,764 KB
testcase_08 AC 121 ms
55,724 KB
testcase_09 AC 120 ms
55,404 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 124 ms
55,992 KB
testcase_13 AC 124 ms
55,764 KB
testcase_14 AC 121 ms
56,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long sum = a + b;
        long ans = -1;
        for (long i = 1; i <= Math.sqrt(sum); i++) {
            if (sum % i == 0) {
                if ((a + i) % b == 0 && (b + i) % a == 0) {
                    ans = i;
                    break;
                }
            } else {
                if ((a + sum / i) % b == 0 && (b + sum / i) % a == 0) {
                    ans = sum / i;
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}
0