0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +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;
bool isprime[1000005];
int n, ans;
int n, p, primes[1000005];
bool not_prime[1000005];
int main() {
cin >> n;
for (int i = 0; i <= n; i++) {
isprime[i] = true;
}
isprime[0] = isprime[1] = false;
for (int i = 2; i <= n; i++) {
if (isprime[i] && 1ll * i * i <= n) {
for (int j = i * i; j <= n; j += i) {
isprime[j] = false;
}
if (!not_prime[i]) {
primes[p++] = i;
}
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++) {
ans += isprime[i];
}
cout << ans;
cout << p << endl;
return 0;
}