結果

問題 No.1946 ロッカーの問題
ユーザー 👑 emthrmemthrm
提出日時 2022-05-20 21:39:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 3,000 ms
コード長 2,449 bytes
コンパイル時間 2,463 ms
コンパイル使用メモリ 207,076 KB
実行使用メモリ 5,880 KB
最終ジャッジ日時 2023-10-20 12:03:52
合計ジャッジ時間 3,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 90 ms
5,876 KB
testcase_03 AC 79 ms
5,880 KB
testcase_04 AC 90 ms
5,876 KB
testcase_05 AC 66 ms
5,240 KB
testcase_06 AC 74 ms
5,460 KB
testcase_07 AC 57 ms
5,016 KB
testcase_08 AC 27 ms
4,348 KB
testcase_09 AC 71 ms
5,640 KB
testcase_10 AC 60 ms
5,324 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 35 ms
4,512 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 31 ms
4,684 KB
testcase_18 AC 61 ms
5,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

std::vector<int> prime_sieve(const int n, const bool get_only_prime) {
  std::vector<int> smallest_prime_factor(n + 1), prime;
  std::iota(smallest_prime_factor.begin(), smallest_prime_factor.end(), 0);
  for (int i = 2; i <= n; ++i) {
    if (smallest_prime_factor[i] == i) prime.emplace_back(i);
    for (const int p : prime) {
      if (i * p > n || p > smallest_prime_factor[i]) break;
      smallest_prime_factor[i * p] = p;
    }
  }
  return get_only_prime ? prime : smallest_prime_factor;
}

struct Divisor {
  const std::vector<int> smallest_prime_factor;

  explicit Divisor(const int n)
      : smallest_prime_factor(prime_sieve(n, false)) {}

  std::vector<int> query(int n) const {
    std::vector<int> res{1};
    while (n > 1) {
      const int prime_factor = smallest_prime_factor[n], d = res.size();
      int tmp = 1;
      for (; n % prime_factor == 0; n /= prime_factor) {
        tmp *= prime_factor;
        for (int i = 0; i < d; ++i) {
          res.emplace_back(res[i] * tmp);
        }
      }
    }
    // std::sort(res.begin(), res.end());
    return res;
  }
};

int main() {
  int n, m; cin >> n >> m;
  vector<int> is_open(n + 1, false);
  while (m--) {
    int a; cin >> a;
    is_open[a] = true;
  }
  Divisor divisor(n);
  vector<int> b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int d : divisor.query(i)) ++b[d];
  }
  int ans = 0;
  for (int i = n; i >= 1; --i) {
    if (is_open[i] != b[i] % 2) {
      ++ans;
      for (int d : divisor.query(i)) --b[d];
    }
  }
  cout << ans << '\n';
  return 0;
}
0