0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 04:18:48 +00:00

P3912 素数个数

R41096436
This commit is contained in:
Baoshuo Ren 2020-11-02 19:59:20 +08:00 committed by Baoshuo Ren
parent d2df3fd8d9
commit 8803ab69fd
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

23
problem/P3912/P3912.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int s = n-1;
bool prime[100000005];
memset(prime, 0, sizeof(prime));
for(int i = 2 ; i*i <= n ; i++) {
if(!prime[i]) {
for(int j = i*2 ; j <= n ; j+= i) {
if(!prime[j]) {
prime[j] = true;
s--;
}
}
}
}
cout << s << endl;
return 0;
}