結果

問題 No.982 Add
ユーザー risujiroh
提出日時 2020-02-11 13:33:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 168,080 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-01 07:20:13
合計ジャッジ時間 2,157 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (__gcd(a, b) == 1) {
    bitset<10010> bs;
    bs[0] = 1;
    for (int i = 0; i < 10010; ++i) {
      if (i + a < 10010 and bs[i]) {
        bs[i + a] = 1;
      }
      if (i + b < 10010 and bs[i]) {
        bs[i + b] = 1;
      }
    }
    int res = 0;
    for (int i = 0; i < 10010; ++i) {
      res += bs[i] == 0;
    }
    cout << res << '\n';
  } else {
    cout << "-1\n";
  }
}
0