結果

問題 No.816 Beautiful tuples
ユーザー tokizotokizo
提出日時 2019-04-20 16:27:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 169,188 KB
実行使用メモリ 197,088 KB
最終ジャッジ日時 2024-04-08 22:13:24
合計ジャッジ時間 6,278 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;

    int ab = a + b;
    vector<bool> F(ab + 1, true);
    for(int i = 1; i <= (int)(sqrt(ab)); i++){
        if(F[i]){
            bool x = (a + b) % i == 0;
            bool y = (b + i) % a == 0;
            bool z = (i + a) % b == 0;
            if(x and y and z){
                cout << i << endl;
                return 0;
            }
            if(i == 1) continue;
            for(int j = i + i; j <= ab; j += i){
                F[j] = false;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}
0