'commit'
This commit is contained in:
24
TangDou/AcWing/Prime/868_1.cpp
Normal file
24
TangDou/AcWing/Prime/868_1.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 1e6 + 10;
|
||||
int primes[N], cnt; // primes[]存储所有素数
|
||||
int st[N]; // st[x]存储x是否被筛掉
|
||||
// 埃拉筛
|
||||
void get_primes(int n) {
|
||||
for (int i = 2; i <= n; i++)
|
||||
if (!st[i]) {
|
||||
primes[cnt++] = i; // 记录素数
|
||||
for (int j = 2 * i; j <= n; j += i)
|
||||
st[j] = 1; // 成倍数的标识
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
get_primes(n);
|
||||
printf("%d\n", cnt);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user