結果

問題 No.106 素数が嫌い!2
ユーザー otsnskotsnsk
提出日時 2014-12-26 21:57:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 59,352 KB
実行使用メモリ 19,252 KB
最終ジャッジ日時 2023-09-03 18:36:37
合計ジャッジ時間 1,916 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
13,668 KB
testcase_01 AC 2 ms
5,416 KB
testcase_02 AC 2 ms
5,608 KB
testcase_03 AC 2 ms
5,424 KB
testcase_04 AC 26 ms
13,604 KB
testcase_05 AC 73 ms
19,184 KB
testcase_06 AC 79 ms
19,252 KB
testcase_07 AC 66 ms
19,160 KB
testcase_08 AC 4 ms
7,964 KB
testcase_09 AC 4 ms
8,072 KB
testcase_10 AC 66 ms
18,968 KB
testcase_11 AC 22 ms
13,608 KB
testcase_12 AC 61 ms
18,724 KB
testcase_13 AC 2 ms
5,452 KB
testcase_14 AC 2 ms
5,440 KB
testcase_15 AC 2 ms
5,404 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 = limit/2 /*(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