結果

問題 No.106 素数が嫌い!2
ユーザー mayoko_mayoko_
提出日時 2014-12-18 23:26:25
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,063 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 75,844 KB
実行使用メモリ 14,676 KB
最終ジャッジ日時 2023-09-02 18:50:33
合計ジャッジ時間 13,121 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define INF 1000000000

using namespace std;
typedef long long ll;

vector<int> prime;
bool isPrime[2100000];

void getPrime() {
    for (int i = 2; i < 2100000; i++) isPrime[i] = true;
    for (int i = 2; i * i < 2100000; i++) {
        if (isPrime[i]) {
            for (int j = 2; j * i < 2100000; j++) {
                isPrime[i*j] = false;
            }
        }
    }
    for (int i = 0; i < 2100000; i++) {
        if (isPrime[i]) prime.push_back(i);
    }
}

int getNum(int n) {
    int ret = 0;
    for (int i = 0; prime[i] <= n; i++) {
        if (n % prime[i] == 0) ret++;
    }
    return ret;
}

int main(void) {
    getPrime();
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 2; i <= n; i++) {
        if (getNum(i) >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}
0