結果

問題 No.816 Beautiful tuples
ユーザー hiro71687khiro71687k
提出日時 2023-08-30 10:17:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 754 bytes
コンパイル時間 4,601 ms
コンパイル使用メモリ 260,064 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 10:17:11
合計ジャッジ時間 6,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0