結果
問題 | No.816 Beautiful tuples |
ユーザー |
|
提出日時 | 2020-04-18 01:31:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,500 ms |
コード長 | 1,173 bytes |
コンパイル時間 | 1,583 ms |
コンパイル使用メモリ | 178,528 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-03 20:32:57 |
合計ジャッジ時間 | 2,277 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#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) break; } 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 == c || b == c) continue; if((a+b) % c == 0) { if((b+c) % a == 0) { if((c+a) % b == 0) { cout << c << "\n"; return 0; } } } } cout << -1 << "\n"; }