結果
問題 | No.106 素数が嫌い!2 |
ユーザー |
|
提出日時 | 2016-04-23 15:25:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 30 ms / 5,000 ms |
コード長 | 808 bytes |
コンパイル時間 | 644 ms |
コンパイル使用メモリ | 68,000 KB |
実行使用メモリ | 12,384 KB |
最終ジャッジ日時 | 2024-10-04 15:20:03 |
合計ジャッジ時間 | 1,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <iostream> #include <vector> #include <cmath> std::vector<int> GetPrimeVec(int n){ std::vector<bool> num(n, true); std::vector<int> prime; num[0]=false; for(int i=0; i<std::sqrt(n); ++i){ if(num[i]){ for(int j=2; (i+1)*j<=n; ++j){ num[(i+1)*j-1] = false; } } } for(int i=0; i<n; ++i){ if(num[i]){ prime.push_back(i+1); } } return prime; } std::vector<int> count(2e6, 0); int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int n, k; std::cin >> n >> k; std::vector<int> primeToN(GetPrimeVec(n)); int ans = 0; for(auto p : primeToN){ for(int i=1; p*i<=n; ++i){ ++count[p*i-1]; } } for(int i=0; i<n; ++i){ if(count[i]>=k) ++ans; } std::cout << ans << "\n"; return 0; }