結果

問題 No.106 素数が嫌い!2
ユーザー ry0u_ydry0u_yd
提出日時 2015-09-02 12:39:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,015 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 71,692 KB
実行使用メモリ 13,136 KB
最終ジャッジ日時 2023-09-25 22:08:16
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,144 KB
testcase_01 AC 4 ms
11,220 KB
testcase_02 AC 4 ms
11,164 KB
testcase_03 AC 4 ms
11,164 KB
testcase_04 AC 15 ms
12,140 KB
testcase_05 AC 32 ms
13,096 KB
testcase_06 AC 32 ms
13,088 KB
testcase_07 AC 32 ms
13,096 KB
testcase_08 AC 5 ms
11,352 KB
testcase_09 AC 5 ms
11,272 KB
testcase_10 AC 32 ms
13,136 KB
testcase_11 AC 13 ms
12,024 KB
testcase_12 AC 30 ms
13,044 KB
testcase_13 AC 4 ms
11,372 KB
testcase_14 AC 4 ms
11,212 KB
testcase_15 AC 5 ms
11,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool prime[10000000];
void Eratosthenes(int n) {
    rep(i,n) prime[i] = true;
    prime[1] = false;

    REP(i,2,(int)sqrt(n)) {
        if(prime[i]) {
            for(int j=0;i*(j+2)<n;j++) {
                prime[i*(j+2)] = 0;
            }
        }
    }
}

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

    Eratosthenes(n+5);
    int cnt[2000005];
    memset(cnt,0,sizeof(cnt));

    REP(i,2,n+1) {
        if(prime[i]) {
            for(int j=i; j <= n; j += i) {
                cnt[j]++;
            }
        }
    }

    int ans = 0;
    REP(i,2,n+1) {
        if(cnt[i] >= k) ans++;
    }

    cout << ans << endl;

    return 0;
}
0