結果

問題 No.106 素数が嫌い!2
ユーザー granddaifukugranddaifuku
提出日時 2020-03-20 12:26:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 576 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 167,012 KB
実行使用メモリ 11,964 KB
最終ジャッジ日時 2023-08-20 21:36:14
合計ジャッジ時間 6,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 221 ms
7,540 KB
testcase_01 AC 1 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
7,620 KB
testcase_05 AC 576 ms
11,916 KB
testcase_06 AC 575 ms
11,788 KB
testcase_07 AC 575 ms
11,884 KB
testcase_08 AC 16 ms
4,380 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 575 ms
11,964 KB
testcase_11 AC 186 ms
7,168 KB
testcase_12 AC 543 ms
11,792 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

bool isPrime(int x) {
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) return false;
    }

    return true;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, k, res = 0;
    cin >> n >> k;
    vector<int> cnt(n + 1), prime;
    FOR (i, 2, n + 1) {
        if (isPrime(i)) prime.push_back(i);
    }
    rep (i, prime.size()) {
        int x = prime[i];
        while (x <= n) {
            cnt[x]++;
            x += prime[i];
        }
    }
    FOR (i, 2, n + 1) if (cnt[i] >= k) res++;
    cout << res << endl;
    
    return 0;
}
0