結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2020-05-09 11:47:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,500 ms |
コード長 | 598 bytes |
コンパイル時間 | 1,547 ms |
コンパイル使用メモリ | 173,560 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 15:43:33 |
合計ジャッジ時間 | 2,303 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; ll y = a + b; vector<ll> ans; for(ll x = 1; x * x <= y; x++){ if(y % x != 0) continue; ll c = x; if(a != c && b != c && (c + a) % b == 0 && (b + c) % a == 0) ans.push_back(c); c = y / x; if(a != c && b != c && (c + a) % b == 0 && (b + c) % a == 0) ans.push_back(c); } if(ans.size() == 0){ cout << -1 << endl; return 0; } sort(ans.begin(), ans.end()); cout << ans[0] << "\n"; }