mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 15:56:26 +00:00
868. 筛质数
https://www.acwing.com/problem/content/submission/code_detail/6873993/
This commit is contained in:
parent
03630f4f07
commit
b09f55411e
26
AcWing/868/868.cpp
Normal file
26
AcWing/868/868.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool isprime[1000005];
|
||||||
|
int n, ans;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
ans += isprime[i];
|
||||||
|
}
|
||||||
|
cout << ans;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user