0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:56:27 +00:00
Baoshuo Ren 2021-08-23 16:15:42 +08:00 committed by Baoshuo Ren
parent 5e13bb1da0
commit 311bc9f385
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -2,25 +2,20 @@
using namespace std; using namespace std;
bool isprime[1000005]; int n, p, primes[1000005];
int n, ans; bool not_prime[1000005];
int main() { int main() {
cin >> n; cin >> n;
for (int i = 0; i <= n; i++) {
isprime[i] = true;
}
isprime[0] = isprime[1] = false;
for (int i = 2; i <= n; i++) { for (int i = 2; i <= n; i++) {
if (isprime[i] && 1ll * i * i <= n) { if (!not_prime[i]) {
for (int j = i * i; j <= n; j += i) { primes[p++] = i;
isprime[j] = false; }
} for (int j = 0; primes[j] * i <= n; j++) {
not_prime[primes[j] * i] = true;
if (i % primes[j] == 0) break;
} }
} }
for (int i = 1; i <= n; i++) { cout << p << endl;
ans += isprime[i];
}
cout << ans;
return 0; return 0;
} }