結果

問題 No.106 素数が嫌い!2
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-04-05 12:19:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 2,590 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 115,240 KB
実行使用メモリ 20,208 KB
最終ジャッジ日時 2023-09-16 06:34:12
合計ジャッジ時間 2,648 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
19,712 KB
testcase_01 AC 45 ms
19,656 KB
testcase_02 AC 46 ms
20,068 KB
testcase_03 AC 47 ms
19,656 KB
testcase_04 AC 46 ms
19,904 KB
testcase_05 AC 50 ms
19,812 KB
testcase_06 AC 51 ms
19,916 KB
testcase_07 AC 47 ms
19,852 KB
testcase_08 AC 46 ms
20,208 KB
testcase_09 AC 48 ms
19,808 KB
testcase_10 AC 47 ms
19,976 KB
testcase_11 AC 45 ms
20,108 KB
testcase_12 AC 52 ms
19,704 KB
testcase_13 AC 45 ms
20,048 KB
testcase_14 AC 45 ms
19,848 KB
testcase_15 AC 45 ms
20,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// 正の整数n未満の素数を全て求める
vector<ll> sieve(ll n) {
  vector<bool> is_prime(n);
  rep(i, n) is_prime[i] = true;

  is_prime[1] = false;
  for (ll i = 4; i < n; i += 2) is_prime[i] = false;
  ll lim = ll(sqrt(n));
  for (ll i = 3; i <= lim; i += 2) {
    for (ll j = 3; i * j < n; j += 2) {
      is_prime[i * j] = false;
    }
  }

  vector<ll> ret;
  for (ll i = 1; i < n; i++) {
    if (is_prime[i]) ret.push_back(i);
  }
  return ret;
}

void solve() {
  const ll MAX = 2 * 1000000;
  vector<ll> p = sieve(MAX);
  vector<ll> nums(MAX+1, 0);
  for (ll pi : p)
    for (int i = pi; i <= MAX; i += pi) nums[i]++;
  
  ll N, K; cin >> N >> K;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    if (nums[i] >= K) ans++;
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}
0