結果

問題 No.982 Add
ユーザー MisterMister
提出日時 2020-02-11 13:38:21
言語 C++17(clang Beta)
(clang 13.0.0 + boost 1.78.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 480 ms
使用メモリ 3,504 KB
最終ジャッジ日時 2023-01-06 20:46:06
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,332 KB
testcase_01 AC 2 ms
3,368 KB
testcase_02 AC 1 ms
3,392 KB
testcase_03 AC 1 ms
3,364 KB
testcase_04 AC 2 ms
3,384 KB
testcase_05 AC 1 ms
3,388 KB
testcase_06 AC 1 ms
3,328 KB
testcase_07 AC 1 ms
3,448 KB
testcase_08 AC 2 ms
3,444 KB
testcase_09 AC 2 ms
3,504 KB
testcase_10 AC 1 ms
3,392 KB
testcase_11 AC 2 ms
3,384 KB
testcase_12 AC 2 ms
3,332 KB
testcase_13 AC 1 ms
3,440 KB
testcase_14 AC 2 ms
3,400 KB
testcase_15 AC 2 ms
3,404 KB
testcase_16 AC 2 ms
3,396 KB
testcase_17 AC 2 ms
3,436 KB
testcase_18 AC 2 ms
3,332 KB
testcase_19 AC 1 ms
3,440 KB
testcase_20 AC 2 ms
3,384 KB
testcase_21 AC 1 ms
3,400 KB
testcase_22 AC 2 ms
3,388 KB
testcase_23 AC 1 ms
3,412 KB
testcase_24 AC 1 ms
3,400 KB
testcase_25 AC 1 ms
3,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

template <class T>
T gcd(T n, T m) {
    while (m != 0) {
        n %= m;
        std::swap(n, m);
    }
    return n;
}

void solve() {
    int a, b;
    std::cin >> a >> b;

    if (gcd(a, b) > 1) {
        std::cout << -1 << std::endl;
        return;
    }

    int m = a * b * 2;
    std::vector<bool> ok(m + 1, true);
    for (int x = 0; a * x <= m; ++x) {
        for (int y = 0; a * x + b * y <= m; ++y) {
            ok[a * x + b * y] = false;
        }
    }

    int ans = std::accumulate(ok.begin(), ok.end(), 0);
    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0