题意:
给定n,找到两个素数,想加得到n,问有多少中方法;
思路:
筛法打个素数表,枚举小于等于(n/2)的所有素数prim[ i ],判(n - prim[ i ])是不是素数
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e7 + 7, maxd = 670000 + 7, mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
int T, n, cnt;
bool p[maxn];
vector<int> prim;
void init() {
memset(p, 1, sizeof p);
for(int i = 4; i < maxn; i += 2) p[i] = 0;
cnt = 0;
prim.push_back(2);
for(int i = 3; i < maxn; i += 2) {
if(p[i]) prim.push_back(i);
for(int j = 0; j < prim.size() && i*prim[j] < maxn; ++j)
p[i*prim[j]] = 0;
}
}
void solve() {
int ans = 0;
for(int i = 0; i < prim.size() && 2*prim[i] <= n; ++i) {
if(p[n-prim[i]]) ans++;
}
cout << ans << endl;
}
int main() {
init();
scanf("%d", &T);
for(int tt = 1; tt <= T; ++tt) {
scanf("%d", &n);
printf("Case %d: ", tt);
solve();
}
return 0;
}