結果

問題 No.106 素数が嫌い!2
ユーザー otsnskotsnsk
提出日時 2014-12-26 21:45:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 61,044 KB
実行使用メモリ 19,048 KB
最終ジャッジ日時 2023-09-03 18:36:11
合計ジャッジ時間 2,335 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
13,600 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,468 KB
testcase_03 AC 2 ms
5,412 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 47 ms
18,980 KB
testcase_07 AC 57 ms
19,016 KB
testcase_08 WA -
testcase_09 AC 4 ms
8,020 KB
testcase_10 AC 47 ms
19,048 KB
testcase_11 AC 17 ms
13,588 KB
testcase_12 WA -
testcase_13 AC 2 ms
5,420 KB
testcase_14 AC 2 ms
5,396 KB
testcase_15 AC 2 ms
5,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <list>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int prime[2000001];
int f[2000001];
int count_factors(int limit, int thres) {
    prime[2] = 1;
    for (int i = 3; i <= limit; i+=2) prime[i] = 1;
    for (int i = 4; i <= limit; i+=2) {
        f[i]++;
    }

    for (int i = 3, l = (int)sqrt(limit)+1; i <= l; i+=2) {
        if (prime[i]) {
            for (int j = i*2; j <= limit; j += i) {
                prime[j] = 0;
                f[j]++;
            }
        }
    }

    int count = 0;
    for (int i = 2; i <= limit; i++) {
        count += (f[i]+prime[i] >= thres);
    }
    return count;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    cout << count_factors(N, K) << "\n";

    return 0;
}
0