結果

問題 No.816 Beautiful tuples
ユーザー GrenacheGrenache
提出日時 2019-04-19 22:34:49
言語 Java19
(openjdk 19.0.1)
結果
AC  
実行時間 104 ms / 1,500 ms
コード長 1,159 bytes
コンパイル時間 5,709 ms
実行使用メモリ 37,876 KB
最終ジャッジ日時 2023-03-31 19:22:44
合計ジャッジ時間 5,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
37,624 KB
testcase_01 AC 98 ms
37,628 KB
testcase_02 AC 98 ms
37,860 KB
testcase_03 AC 102 ms
37,780 KB
testcase_04 AC 102 ms
37,780 KB
testcase_05 AC 99 ms
37,808 KB
testcase_06 AC 98 ms
37,788 KB
testcase_07 AC 100 ms
37,792 KB
testcase_08 AC 97 ms
37,824 KB
testcase_09 AC 98 ms
37,640 KB
testcase_10 AC 100 ms
37,652 KB
testcase_11 AC 104 ms
37,872 KB
testcase_12 AC 104 ms
37,756 KB
testcase_13 AC 100 ms
37,876 KB
testcase_14 AC 98 ms
37,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
		}
	}
}
0