Bryce1010模板
2.1.1 素数筛选(判断 < MAXN的数是否是素数)
const int MAXN = 1000010;
bool notprime[MAXN];
void init()
{
memset(notprime, false, sizeof(notprime));
notprime[0] = notprime[1] = true;
for (int i = 2; i < MAXN; i++)
{
if (!notprime[i])
{
if (i > MAXN / i)
{
continue;
}
for (int j = i * i; j < MAXN; j += i)
{
notprime[j] = true;
}
}
}
}
2.1.2 素数筛选(筛选小于等于MAXN的素数)
const int MAXN = 100000;
int prime[MAXN + 1];
void getPrime()
{
memset(prime, 0, sizeof(prime));
for (int i = 2; i <= MAXN; i++)
{
if (!prime[i])
{
prime[++prime[0]] = i;
}
for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++)
{
prime[prime[j] * i] = 1;
if (i % prime[j] == 0)
{
break;
}
}
}
}