結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2020-01-22 17:54:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,500 ms |
コード長 | 958 bytes |
コンパイル時間 | 1,203 ms |
コンパイル使用メモリ | 101,532 KB |
最終ジャッジ日時 | 2025-01-08 20:26:28 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; using P = pair<int, int>; const long long MOD = 1e9+7; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } vector<int> divisor(int n) { vector<int> res; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } return res; } int main() { int a, b; cin >> a >> b; vector<int> ds = divisor(a + b); for (auto d : ds) { if (d == a || d == b) continue; if ((a + d) % b == 0 && (b + d) % a == 0) { cout << d << endl; return 0; } } cout << -1 << endl; }