Eratosthenes筛计算N以内的素数
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> GetPrimeNumber(const int N)
{
vector<int> b;
int* a = new int[N+1];
a[1] = false;
for (int i = 2; i < N + 1; i++)
{
a[i] = true;
}
int p = 2;
int j = p*p;
while (j <= N)
{
while (j<=N)
{
a[j] = false;
j += p;
}
p++;
while (a[p]==false)
{
p++;
}
j = p*p;
}
for (int i = 2; i < N + 1; i++)
{
if (a[i]==true)
{
b.push_back(i);
}
}
return b;
}
int main()
{
int N = 100;
vector<int> b= GetPrimeNumber(N);
}