結果

問題 No.106 素数が嫌い!2
ユーザー face4
提出日時 2018-05-20 17:32:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 1,096 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 75,204 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-06-28 14:43:36
合計ジャッジ時間 1,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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