結果

問題 No.816 Beautiful tuples
ユーザー legosuke
提出日時 2020-11-12 21:10:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 548 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 197,972 KB
最終ジャッジ日時 2025-01-15 22:17:24
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main() {
    int A, B;
    cin >> A >> B;
    for (int C : divisor(A + B)) if (C != A && C != B) {
        if ((A + C) % B == 0 && (B + C) % A == 0) {
            cout << C << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}
0