結果

問題 No.816 Beautiful tuples
ユーザー sykwersykwer
提出日時 2019-04-19 21:31:03
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,417 bytes
コンパイル時間 968 ms
使用メモリ 3,504 KB
最終ジャッジ日時 2022-11-22 06:11:12
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
vector<int> divisor(int n) {
    vector<int> ret;

    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }

    return move(ret);
}

signed main() {
    int A, B;
    cin >> A >> B;
    vector<int> divs = divisor(A + B);
    sort(divs.begin(), divs.end());
    for (int div : divs) {
        if (div == A || div == B) continue;
        if ((B + div) % A == 0 && (div + A) % B == 0) {
            cout << div << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}
0