結果
| 問題 | No.816 Beautiful tuples | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-18 01:24:03 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,106 bytes | 
| コンパイル時間 | 1,896 ms | 
| コンパイル使用メモリ | 180,208 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-03 20:20:28 | 
| 合計ジャッジ時間 | 2,803 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 WA * 4 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llong long long
int main() {
    llong a, b;
    cin >> a >> b;
    vector<llong> divisors;
    llong val = a + b;
    llong limit = (llong)sqrt(val)+1LL;
    for(llong i=2; i<=limit; i++) {
        while(val % i == 0 && val > 1) {
            val /= i;
            divisors.push_back(i);
        }
    }
    if(val > 1) divisors.push_back(val);
    vector<llong> cands;
    set<llong> checked;
    cands.push_back(1);
    checked.insert(1);
    for(llong d: divisors) {
        int lim = cands.size();
        rep(i, lim) {
            llong val = cands[i] * d;
            if(checked.count(val)) continue;
            checked.insert(val);
            cands.push_back(val);
        }
    }
    sort(cands.begin(), cands.end());
    for(llong c: cands) {
        if((a+b) % c == 0) {
            if((b+c) % a == 0) {
                if((c+a) % b == 0) {
                    cout << c << "\n";
                    return 0;
                }
            }
        }
    }
    cout << -1 << "\n";
}
            
            
            
        