結果

問題 No.982 Add
ユーザー Forested
提出日時 2020-06-03 11:12:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 93,568 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 02:42:28
合計ジャッジ時間 1,795 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int GCD(int x, int y) {if (x % y) return GCD(y, x % y); return y;}

int main() {
    int A, B;
    cin >> A >> B;
    if (GCD(A, B) - 1) {
        cout << -1 << "\n";
        return 0;
    }
    vector<int> judge(A * B, 0);
    rep(i, B) {
        int now = A * i;
        while (now < A * B) {
            judge[now] = 1;
            now += B;
        }
    }
    int ans = 0;
    rep(i, A * B) {
        if (!judge[i]) ++ans;
    }
    cout << ans << "\n";
    return 0;
}
0