結果
問題 | No.816 Beautiful tuples |
ユーザー |
|
提出日時 | 2019-04-19 22:34:49 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 139 ms / 1,500 ms |
コード長 | 1,159 bytes |
コンパイル時間 | 3,691 ms |
コンパイル使用メモリ | 78,100 KB |
実行使用メモリ | 54,272 KB |
最終ジャッジ日時 | 2024-09-22 22:24:40 |
合計ジャッジ時間 | 6,474 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
import java.io.*; import java.util.Scanner; public class Main_yukicoder816 { private static Scanner sc; private static Printer pr; private static void solve() { int a = sc.nextInt(); int b = sc.nextInt(); int ab = a + b; for (long c = 1; c * c <= ab; c++) { if (ab % c == 0) { if (check(a, b, c)) { pr.println(c); return; } if (c != ab / c) { if (check(a, b, ab / c)) { pr.println(ab / c); return; } } } } pr.println(-1); } private static boolean check(int a, int b, long c) { if (a == b || b == c || c == a) { return false; } if ((a + b) % c == 0 && (b + c) % a == 0 && (c + a) % b == 0) { return true; } else { return false; } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes())); pr = new Printer(System.out); solve(); // pr.close(); pr.flush(); // sc.close(); } static String INPUT = null; private static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }