結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,888 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 15 ms
11,904 KB
testcase_05 AC 34 ms
19,028 KB
testcase_06 AC 35 ms
19,024 KB
testcase_07 AC 34 ms
18,968 KB
testcase_08 AC 4 ms
6,304 KB
testcase_09 AC 4 ms
6,360 KB
testcase_10 AC 34 ms
19,032 KB
testcase_11 AC 14 ms
11,900 KB
testcase_12 AC 32 ms
18,408 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,372 KB
testcase_15 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

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

int main(){
    int N, K;
    cin >> N >> K;
    
    int res = 0;
    for(int i=2;i<=N;i++){
        if(maxp[i] == 0){
            for(int kp=i;kp<=N;kp+=i)maxp[kp] = i;
            cnt[i] = 1;
        } else {
            int mp = maxp[i];
            if(maxp[i / mp] == mp){
                cnt[i] = cnt[i / mp];
            } else {
                cnt[i] = cnt[i / mp] + 1;
            }
        }
     
        if(cnt[i] >= K)++res;
    }
    
    cout << res << endl;
    return 0;
}
0