結果

問題 No.106 素数が嫌い!2
ユーザー krotonkroton
提出日時 2014-12-18 23:22:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 793 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 51,660 KB
実行使用メモリ 21,292 KB
最終ジャッジ日時 2023-09-02 18:49:32
合計ジャッジ時間 1,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
16,072 KB
testcase_01 AC 2 ms
7,444 KB
testcase_02 AC 2 ms
7,728 KB
testcase_03 AC 2 ms
7,704 KB
testcase_04 AC 15 ms
15,920 KB
testcase_05 AC 28 ms
21,208 KB
testcase_06 AC 28 ms
21,240 KB
testcase_07 AC 28 ms
21,228 KB
testcase_08 AC 4 ms
9,628 KB
testcase_09 AC 4 ms
9,540 KB
testcase_10 AC 29 ms
21,292 KB
testcase_11 AC 14 ms
15,924 KB
testcase_12 AC 28 ms
20,976 KB
testcase_13 AC 2 ms
7,456 KB
testcase_14 AC 2 ms
7,460 KB
testcase_15 AC 3 ms
7,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int N_MAX = 2000000;
int min_p[N_MAX + 10], cnt[N_MAX + 10], ps[N_MAX + 10];

int main(){
    int N, K;
    cin >> N >> K;
    
    int res = 0;
    int ps_size = 0;

    for(int n=2;n<=N;n++)min_p[n] = n;
    for(int n=2;n<=N;n++){
        if(min_p[n] == n){
        	cnt[n] = 1;
        	ps[ps_size++] = n;
        } else {
        	int mp = min_p[n];
        	if(min_p[n / mp] == mp){
        		cnt[n] = cnt[n / mp];
        	} else {
        		cnt[n] = cnt[n / mp] + 1;
        	}
        }

        for(int i=0;i<ps_size;i++){
        	if(ps[i] > min_p[n])break;

        	int np = n * ps[i];
        	if(np > N)break;

        	min_p[np] = ps[i];
        }

        if(cnt[n] >= K)++res;
    }
    
    cout << res << endl;
    return 0;
}
0