結果

問題 No.106 素数が嫌い!2
ユーザー face4face4
提出日時 2018-05-20 17:32:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 1,096 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 11,244 KB
最終ジャッジ日時 2023-09-11 00:05:15
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,020 KB
testcase_01 AC 28 ms
10,916 KB
testcase_02 AC 30 ms
10,924 KB
testcase_03 AC 29 ms
10,996 KB
testcase_04 AC 29 ms
11,044 KB
testcase_05 AC 31 ms
11,112 KB
testcase_06 AC 30 ms
10,988 KB
testcase_07 AC 30 ms
10,968 KB
testcase_08 AC 29 ms
11,084 KB
testcase_09 AC 31 ms
10,936 KB
testcase_10 AC 31 ms
11,112 KB
testcase_11 AC 29 ms
11,244 KB
testcase_12 AC 35 ms
11,052 KB
testcase_13 AC 30 ms
11,064 KB
testcase_14 AC 28 ms
11,052 KB
testcase_15 AC 31 ms
10,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int main(){
    vector<int> factor(2e6+1, 0);
    vector<bool> nonprime(2e6+1, false); // 実はnonprimeではない(int j = i+iではなくiとしているため)
    for(int i = 2; i < 2e6+1; i++){
        if(!nonprime[i]){
            for(int j = i; j < 2e6+1; j+=i){
                nonprime[j] = true;
                factor[j]++;
            }
        }
    }

    int n, k;
    cin >> n >> k;
    int cnt = 0;
    for(int i = 2; i <= n; i++){
        if(factor[i] >= k)    cnt++;
    }

    cout << cnt << endl;
    return 0;
}

// 3560ms(!!)
// int count(int n){
//     int cnt = 0;
//     for(int i = 2; i <= sqrt(n); i++){
//         if(n%i == 0){
//             cnt+=1;
//             n/=i;
//             while(n%i == 0) n/=i;
//         }
//     }
//     if(n != 1)  cnt++;
//     return cnt;
// }

// int main(){
//     int n, k;
//     cin >> n >> k;
//     int ans = n-1;

//     for(int i = 2; i <= n; i++){
//         if(count(i) < k)    ans--;
//     }

//     cout << ans << endl;
//     return 0;
// }
0