結果
問題 | No.106 素数が嫌い!2 |
ユーザー | satanic |
提出日時 | 2016-04-23 15:25:08 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 33 ms / 5,000 ms |
コード長 | 808 bytes |
コンパイル時間 | 577 ms |
コンパイル使用メモリ | 67,976 KB |
実行使用メモリ | 12,388 KB |
最終ジャッジ日時 | 2024-04-15 04:18:56 |
合計ジャッジ時間 | 1,439 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
11,708 KB |
testcase_01 | AC | 5 ms
10,960 KB |
testcase_02 | AC | 4 ms
10,972 KB |
testcase_03 | AC | 4 ms
10,900 KB |
testcase_04 | AC | 17 ms
11,632 KB |
testcase_05 | AC | 32 ms
12,384 KB |
testcase_06 | AC | 32 ms
12,380 KB |
testcase_07 | AC | 32 ms
12,384 KB |
testcase_08 | AC | 5 ms
11,064 KB |
testcase_09 | AC | 6 ms
11,120 KB |
testcase_10 | AC | 33 ms
12,388 KB |
testcase_11 | AC | 14 ms
11,632 KB |
testcase_12 | AC | 31 ms
12,372 KB |
testcase_13 | AC | 4 ms
10,940 KB |
testcase_14 | AC | 4 ms
10,896 KB |
testcase_15 | AC | 4 ms
10,876 KB |
ソースコード
#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; }