結果
問題 | No.106 素数が嫌い!2 |
ユーザー |
|
提出日時 | 2015-01-16 15:47:48 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 1,656 bytes |
コンパイル時間 | 1,503 ms |
コンパイル使用メモリ | 161,256 KB |
実行使用メモリ | 13,016 KB |
最終ジャッジ日時 | 2024-06-22 12:04:07 |
合計ジャッジ時間 | 2,693 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s)) #define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1)) #define rep(i,n) iota(i,(n),0,1) #define loop for(;;) #define INF (1e9) #define EPS (1e-9) #define cons(a,b) (make_pair(a,b)) #define car(a) (a.first) #define cdr(a) (a.second) #define cadr(a) (car(cdr(a))) #define cddr(a) (cdr(cdr(a))) #define all(a) a.begin(), a.end() #define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl; typedef long long Integer; typedef double Real; typedef vector<int> vi; typedef vector<string> vs; typedef map<string,int> Dictionary; const Real PI = acos(-1); typedef pair<Real, Real> P; // Point typedef pair<P, P> L; // segment or line template<class S, class T> ostream& operator<<(ostream& os, pair<S,T> p) { os << '(' << car(p) << ", " << cdr(p) << ')'; return os; } template<class T> ostream& operator<<(ostream& os, vector<T> v) { if (v.size() == 0) { os << "(empty)"; return os; } os << v[0]; for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i]; return os; } bool* PrimeSieve(int n) { bool*s = new bool[n]; for (int i = 0; i < n; ++i) s[i] = true; s[0] = s[1] = false; for (int i = 2; i < n; ++i) if (s[i]) for (int j = i << 1; j < n; j += i) s[j] = false; return s; } int main(){ auto ps = PrimeSieve(2e6+10); int n, k; cin >> n >> k; vector<int> cs(n+1, 0); range (m, 2, n + 1) { if (ps[m]) { for (int k = m; k <= n; k += m) cs[k]++; } } int ans = 0; range (m, 2, n + 1) { if (cs[m] >= k) ++ans; } cout << ans << endl; return 0; }