結果

問題 No.816 Beautiful tuples
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-19 21:47:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 640 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 74,236 KB
実行使用メモリ 54,360 KB
最終ジャッジ日時 2024-04-15 10:48:13
合計ジャッジ時間 4,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 138 ms
54,200 KB
testcase_02 AC 137 ms
53,716 KB
testcase_03 WA -
testcase_04 AC 137 ms
53,740 KB
testcase_05 AC 137 ms
54,200 KB
testcase_06 AC 138 ms
54,088 KB
testcase_07 AC 138 ms
53,884 KB
testcase_08 AC 140 ms
54,268 KB
testcase_09 AC 139 ms
54,360 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 138 ms
53,952 KB
testcase_13 AC 137 ms
54,356 KB
testcase_14 AC 139 ms
54,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long ans = (long)Math.pow(10, 18) + 1;
    for(long i = 1; (i * i) <= (a + b); i++) {
      if(((a + b) % i) == 0) {
        long t = (a + b) / i;
        if((((b + i) % a) == 0) && (((a + i) % b) == 0)) {
          ans = Math.min(ans, i);
        }
        if((((b + t) % a) == 0) && (((a + t) % b) == 0)) {
          ans = Math.min(ans, t);
        }
      }
    }
    if(ans == ((long)Math.pow(10, 18) + 1)) ans = -1;
    System.out.println(ans);
  }
}
0