题意:求把偶数n拆成两个不同素数和的拆发有多少种。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
using namespace std;
const int maxn = 1e4 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = 4 * atan(1.0);
const double ee = exp(1.0);
int prime[maxn];
bool isprime[maxn];
int nprime;
void doprime()
{
int m = sqrt(maxn + 0.5);
nprime = 0;
memset(isprime, true, sizeof(isprime));
for (int i = 2; i <= m; i++)
{
if (isprime[i])
{
prime[++nprime] = i;
for (int j = 2 * i; j <= maxn; j+= i)
{
isprime[j] = false;
}
}
}
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
doprime();
int n;
while (scanf("%d", &n) && n)
{
int ans = 0;
for (int i = 2; i < n / 2; i++)
{
if (isprime[i] && isprime[n - i])
{
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}