結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2023-08-30 10:17:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 754 bytes |
コンパイル時間 | 4,212 ms |
コンパイル使用メモリ | 250,772 KB |
最終ジャッジ日時 | 2025-02-16 15:37:34 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=1000000007; ll inf=10099999999999990; int main(){ ll a,b; cin >> a >> b; ll x=a+b; vector<ll>y; for (ll i = 1; i*i <=x; i++) { if (x%i==0) { y.push_back(i); y.push_back(x/i); } } ll ans=inf; for (ll i = 0; i < y.size(); i++) { if (y[i]==a||y[i]==b) { continue; } if ((y[i]+a)%b==0&&(y[i]+b)%a==0) { ans=min(ans,y[i]); } } if (ans==inf) { cout << -1 << endl; }else{ cout << ans << endl; } }