結果

問題 No.816 Beautiful tuples
ユーザー hiroahiroa
提出日時 2019-05-02 16:37:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 556 bytes
コンパイル時間 1,283 ms
コンパイル使用メモリ 146,536 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 04:48:31
合計ジャッジ時間 2,713 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9

vector<int> divisor(int n){
    vector<int> res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i) res.push_back(n/i);
        }
    }
    return res;
}

int main(){
    int A,B;
    cin>>A>>B;
    vector<int> r=divisor(A+B);
    for(int i=0;i<r.size();i++){
        if((B+r[i])%A==0 && (r[i]+A)%B==0){
            cout<<r[i]<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    
}
0