結果

問題 No.106 素数が嫌い!2
ユーザー kyo1kyo1
提出日時 2020-11-25 17:24:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 458 ms / 5,000 ms
コード長 942 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 205,796 KB
実行使用メモリ 10,840 KB
最終ジャッジ日時 2023-10-01 01:48:24
合計ジャッジ時間 6,763 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
6,936 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 222 ms
6,924 KB
testcase_05 AC 450 ms
10,840 KB
testcase_06 AC 458 ms
10,704 KB
testcase_07 AC 446 ms
10,800 KB
testcase_08 AC 30 ms
4,380 KB
testcase_09 AC 33 ms
4,376 KB
testcase_10 AC 450 ms
10,680 KB
testcase_11 AC 197 ms
6,444 KB
testcase_12 AC 430 ms
10,484 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

class SieveOfEratosthenes {
 private:
  std::vector<int> sieve;

 public:
  SieveOfEratosthenes(int n) : sieve(n + 1) {
    std::iota(sieve.begin(), sieve.end(), 0);
    for (int i = 2; i * i < n + 1; i++) {
      if (sieve[i] != i) continue;
      for (int j = i * i; j < n + 1; j += i) {
        if (sieve[j] == j) sieve[j] = i;
      }
    }
  }

  bool is_prime(int x) const { return x != 0 && x != 1 && sieve[x] == x; }

  int factor(int x) const {
    std::vector<int> res;
    set<int> st;
    while (x > 1) {
      res.emplace_back(sieve[x]);
      st.insert(sieve[x]);
      x /= sieve[x];
    }
    return (int)st.size();
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  SieveOfEratosthenes soe(N + 1);
  int res = 0;
  for (int i = 0; i < N + 1; i++) {
    if (soe.factor(i) >= K) res++;
  }
  cout << res << '\n';
  return 0;
}
0