結果

問題 No.816 Beautiful tuples
ユーザー nebukuro09nebukuro09
提出日時 2019-04-19 21:29:37
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 670 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 101,236 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 00:41:12
合計ジャッジ時間 1,283 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!long);
    auto A = s[0];
    auto B = s[1];

    long ans =10L^^18 + 10;

    bool ok(long C) {
        return (A + B) % C == 0 && (B + C) % A == 0 && (C + A) % B == 0 && A != C && B != C;
    }

    for (long i = 1; i * i <= A + B; ++i) {
        if ((A + B) % i != 0) continue;
        if (ok(i)) ans = min(ans, i);
        if (ok(((A+B)/i))) ans = min(ans, (A+B)/i);
    }

    writeln(ans == 10L^^18 + 10 ? -1 : ans);
}
0