結果

問題 No.816 Beautiful tuples
ユーザー GrenacheGrenache
提出日時 2019-04-19 22:34:49
言語 Java19
(openjdk 21)
結果
AC  
実行時間 133 ms / 1,500 ms
コード長 1,159 bytes
コンパイル時間 4,151 ms
コンパイル使用メモリ 78,368 KB
実行使用メモリ 57,724 KB
最終ジャッジ日時 2023-10-24 05:33:03
合計ジャッジ時間 6,162 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,152 KB
testcase_01 AC 131 ms
57,412 KB
testcase_02 AC 130 ms
57,428 KB
testcase_03 AC 130 ms
57,192 KB
testcase_04 AC 118 ms
56,292 KB
testcase_05 AC 130 ms
57,164 KB
testcase_06 AC 131 ms
57,180 KB
testcase_07 AC 131 ms
57,708 KB
testcase_08 AC 133 ms
57,520 KB
testcase_09 AC 131 ms
57,496 KB
testcase_10 AC 131 ms
57,292 KB
testcase_11 AC 129 ms
57,464 KB
testcase_12 AC 130 ms
57,724 KB
testcase_13 AC 132 ms
57,672 KB
testcase_14 AC 126 ms
57,460 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