結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2020-12-30 00:40:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 600 bytes |
コンパイル時間 | 3,183 ms |
コンパイル使用メモリ | 194,332 KB |
最終ジャッジ日時 | 2025-01-17 08:23:17 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int64_t A, B; cin >> A >> B; vector<int64_t> C; for (int64_t i = 1; i * i < A + B + 1; i++) { if ((A + B) % i == 0) { C.emplace_back(i); C.emplace_back((A + B) / i); } } int64_t res = INT64_C(1) << 50; for (const auto &c : C) { if (A != c && B != c && (A + B) % c == 0 && (A + c) % B == 0 && (B + c) % A == 0) res = min(res, c); } if (res != INT64_C(1) << 50) { cout << res << '\n'; } else { cout << -1 << '\n'; } return 0; }