結果

問題 No.816 Beautiful tuples
ユーザー ks2m
提出日時 2019-04-19 21:36:03
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 471 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 74,676 KB
実行使用メモリ 54,396 KB
最終ジャッジ日時 2024-09-22 17:04:26
合計ジャッジ時間 5,149 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int max = (int) Math.sqrt(a + b);
		for (int i = 1; i <= max; i++) {
			if (a == i || b == i) {
				continue;
			}
			if ((a + b) % i == 0 && (a + i) % b == 0 && (i + b) % a == 0) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
}
0