結果

問題 No.816 Beautiful tuples
ユーザー chocoruskchocorusk
提出日時 2019-04-20 07:03:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 509 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 66,296 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 08:02:15
合計ジャッジ時間 1,681 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll a, b;
    cin>>a>>b;
    vector<ll> d;
    for(ll c=1; c*c<=a+b; c++){
        if((a+b)%c==0){
            d.push_back(c);
            if(c*c<a+b) d.push_back((a+b)/c);
        }
    }
    sort(d.begin(), d.end());
    for(auto c:d){
        if((a+c)%b==0 && (b+c)%a==0 && c!=a && c!=b){
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}
0