結果
問題 | No.816 Beautiful tuples |
ユーザー | treeone |
提出日時 | 2019-04-19 21:29:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,500 ms |
コード長 | 675 bytes |
コンパイル時間 | 2,192 ms |
コンパイル使用メモリ | 192,548 KB |
最終ジャッジ日時 | 2025-01-07 02:37:59 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define int long long using namespace std; typedef pair<int, int> P; const int mod = 1000000007; const int INF = 1e18; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int a, b; cin >> a >> b; int c = INF; for(int i = 1; i * i <= a + b; i++){ if((a + b) % i == 0){ if((a + i) % b == 0 && (i + b) % a == 0 && i != a && i != b) c = min(c, i); int j = (a + b) / i; if((a + j) % b == 0 && (j + b) % a == 0 && j != a && j != b) c = min(c, j); } } if(c == INF) cout << -1 << endl; else cout << c << endl; }