結果

問題 No.816 Beautiful tuples
ユーザー springrollspringroll
提出日時 2019-04-19 21:47:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 1,081 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 171,072 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 01:24:20
合計ジャッジ時間 2,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 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 2 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 3 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define MAX_N (200005)
#define INF (1LL<<60)
#define debug(x) cerr << #x <<":"<< x << endl;
#define debugVec(x) for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define debugVecPair(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<" "<< p.second << endl;
#define debugIdx(i, x) cerr << #i <<" : "<< i <<" "<< #x <<" : "<< x << endl;
const int MOD = (int)1e9+7;

// 約数の列挙O(√n)
vector<int> divisor(int n){
    vector<int> res;
    for(int i=1; i*i<=n; i++){
        if(n%i==0){
            res.push_back(i);
            // n の約数が i の時、n/i も n の約数になる
            if(i!=n/i) res.push_back(n/i);
        }
    }
    return res;
}

signed main() {
    int A, B;
    cin >> A >> B;
    vector<int> C;
    C = divisor(A+B);
    int ans=INF;
    for(int i=0; i<C.size(); i++){
        //debug(C[i]);
        if(A==C[i] || B==C[i] || A==B) continue;
        if((A+C[i])%B==0 && (B+C[i])%A==0){
            ans = min(ans, C[i]);
        }
    }
    cout << (ans==INF?-1:ans) << endl;
}
0