1 solutions
-
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; vector<int> a(n); int maxv = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] > maxv) maxv = a[i]; } int limit = max(2, maxv); vector<char> is_prime(limit + 1, true); is_prime[0] = is_prime[1] = false; for (int p = 2; 1LL * p * p <= limit; ++p) { if (is_prime[p]) { for (int q = p * p; q <= limit; q += p) is_prime[q] = false; } } int cnt = 0; for (int x : a) if (x >= 0 && x <= limit && is_prime[x]) ++cnt; cout << cnt << '\n'; return 0; }
Information
- ID
- 7101
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 2
- Tags
- # Submissions
- 115
- Accepted
- 7
- Uploaded By