代码:
接口: primeInit(100000);//打表的范围
素数存在primeList中,个数为primeCount
typedef long long LL;
int const MAXN = 10000100;
bool isPrime[MAXN];
LL primeList[MAXN/10],primeCount = 0;
void primeInit(LL n)
{
memset(isPrime,true,sizeof(isPrime));//初始化认为全部是素数
int m = sqrt(n + 0.5);
isPrime[1] = false;
for(int i = 2; i <= m; i ++)
{
if(isPrime[i])//判断是素数
{
for(int j = i * i; j <= n; j += i){
isPrime[j] = false;
}
}
}
for(int i = 2; i <= n; i ++)
{
if(isPrime[i]){
primeList[primeCount] = i;
primeCount ++;
}
}
}
代码:接口primeInit(n)//n表示要求素数的范围
typedef long long LL;
int const MAXN = 10000100;
bool isPri