結果

問題 No.816 Beautiful tuples
ユーザー tokizotokizo
提出日時 2019-04-20 16:48:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 734 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 172,968 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 22:39:06
合計ジャッジ時間 2,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 x = a + b;

    vector<int> A;
    for(int i = 1; i <= (int)(sqrt(x)); i++){
        if(x % i == 0){
            A.push_back(i);
            A.push_back(x / i);
        }
    }

    sort(A.begin(), A.end());

    for(int i = 0; i < A.size(); i++){
        if(A[i] != a and A[i] != b){
            bool l = (a + b) % A[i] == 0;
            bool m = (b + A[i]) % a == 0;
            bool n = (A[i] + a) % b == 0;
            if(l and m and n){
                cout << A[i] << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}
0