标签:int ldb pre can turn oid strong com www
#include<cstdio>
const int maxn = 1e7 + 10;
bool no_prime[maxn];
int prime[(int)7e5];
int shai(int n)
{
int cnt = 0;
no_prime[1] = 1;
for (int i = 2; i <= n; i++)
{
if (!no_prime[i])
prime[++cnt] = i;
for (int j = 1; j <= n && prime[j] * i <= n; j++)
{
no_prime[prime[j] * i] = 1;
if (i % prime[j] == 0) break;
}
}
return cnt;
}
void solve()
{
int cnt = shai(maxn - 10);
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++)
{
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 1; i <= cnt && prime[i] < n && prime[i] <= n - prime[i]; i++)
{
if (!no_prime[n - prime[i]])
ans++;
}
printf("Case %d: %d\n", i, ans);
}
}
int main()
{
freopen("Testin.txt", "r", stdin);
solve();
return 0;
}
LightOJ1259 Goldbach`s Conjecture 线性筛
标签:int ldb pre can turn oid strong com www
原文地址:https://www.cnblogs.com/danzh/p/11419282.html