'commit'
This commit is contained in:
25
TangDou/KaoShi/埃拉筛.cpp
Normal file
25
TangDou/KaoShi/埃拉筛.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
const int N = 1e5 + 10;
|
||||
int primes[N], cnt; // primes[]存储所有素数
|
||||
bool 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] = true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
get_primes(200);
|
||||
for (int i = 0; i < cnt; i++)
|
||||
if (primes[i] > 100)
|
||||
cout << primes[i] << " ";
|
||||
*/
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user