結果

問題 No.816 Beautiful tuples
ユーザー bamboo_circlebamboo_circle
提出日時 2019-04-19 21:31:45
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 874 bytes
コンパイル時間 948 ms
使用メモリ 3,556 KB
最終ジャッジ日時 2022-11-22 06:14:39
合計ジャッジ時間 1,915 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	ll a,b;
    cin >> a >> b;
    ll ans = -1;
    ll ab = a + b;
    for(int i = 1; i * i <= ab; i++){
        if(ab % i != 0) continue;

        ll next = ab / i;
        if((i+a)%b == 0 && (i+b)%a == 0){
            ans = i;
            break;
        } 
        if((next+a)%b == 0 && (next+b)%a == 0){
            ans = next;
            break;
        } 
    }
    cout << ans << endl;
}
0