結果

問題 No.106 素数が嫌い!2
ユーザー tnakao0123tnakao0123
提出日時 2016-03-16 22:48:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,075 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 84,888 KB
実行使用メモリ 13,288 KB
最終ジャッジ日時 2024-04-08 16:38:38
合計ジャッジ時間 1,677 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
11,240 KB
testcase_01 WA -
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 32 ms
13,288 KB
testcase_07 AC 32 ms
13,288 KB
testcase_08 WA -
testcase_09 AC 5 ms
6,980 KB
testcase_10 AC 31 ms
13,288 KB
testcase_11 AC 15 ms
11,240 KB
testcase_12 WA -
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 106.cc: No.106 素数が嫌い!2 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000000;

/* typedef */

/* global variables */

bool primes[MAX_N + 1];
int pcnts[MAX_N + 1];

/* subroutines */

void gen_primes(int maxp) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pcnts[p]++;
      for (int q = p * 2; q <= maxp; q += p)
	primes[q] = false, pcnts[q]++;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pcnts[p]++;
}

/* main */

int main() {
  int n, k;
  cin >> n >> k;

  gen_primes(n);

  int cnt = 0;
  for (int i = 2; i <= n; i++)
    if (pcnts[i] >= k) cnt++;

  printf("%d\n", cnt);
  return 0;
}
0