結果

問題 No.816 Beautiful tuples
ユーザー merom686merom686
提出日時 2019-04-19 21:28:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 541 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 73,880 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 16:30:07
合計ジャッジ時間 1,298 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

void f(ll a, ll b, ll c) {
    if ((a + c) % b == 0 && (c + b) % a == 0) {
        cout << c << endl;
        exit(0);
    }
}

int main() {
    ll a, b;
    cin >> a >> b;

    ll c = a + b;

    for (ll i = 1; i * i <= c; i++) {
        if (c % i == 0) {
            f(a, b, i);
            f(a, b, c / i);
        }
    }

    cout << -1 << endl;

    return 0;
}
0