結果

問題 No.816 Beautiful tuples
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-19 23:10:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 1,500 ms
コード長 690 bytes
コンパイル時間 2,462 ms
コンパイル使用メモリ 77,484 KB
実行使用メモリ 41,588 KB
最終ジャッジ日時 2024-04-15 12:57:32
合計ジャッジ時間 5,418 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
41,448 KB
testcase_01 AC 139 ms
41,116 KB
testcase_02 AC 140 ms
41,392 KB
testcase_03 AC 139 ms
41,280 KB
testcase_04 AC 139 ms
41,460 KB
testcase_05 AC 138 ms
41,068 KB
testcase_06 AC 138 ms
41,124 KB
testcase_07 AC 137 ms
41,444 KB
testcase_08 AC 135 ms
41,396 KB
testcase_09 AC 139 ms
41,096 KB
testcase_10 AC 138 ms
41,508 KB
testcase_11 AC 137 ms
41,280 KB
testcase_12 AC 140 ms
41,300 KB
testcase_13 AC 140 ms
41,464 KB
testcase_14 AC 139 ms
41,588 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)) {
          if((i != a) && (i != b)) ans = Math.min(ans, i);
        }
        if((((b + t) % a) == 0) && (((a + t) % b) == 0)) {
          if((t != a) && (t != b)) ans = Math.min(ans, t);
        }
      }
    }
    if(ans == ((long)Math.pow(10, 18) + 1)) ans = -1;
    System.out.println(ans);
  }
}
0