将一个偶数拆成两个素数的和,欧拉筛暴力
1 #include<stdio.h>
2 #include<string.h>
3 #define N 10001
4 int prime[10001];
5 bool check[10001];
6 int n,i,ans,tot=0,j;
7
8 void EulerPrime(){
9 memset(check,false,sizeof(check));
10 for(i=2;i<=N;i++){
11 if(!(check[i]))prime[tot++]=i;
12 for(j=0;j<tot;j++){
13 if(i*prime[j]>N)break;
14 check[i*prime[j]]=true;
15 if(i%prime[j]==0)break;
16 }
17 }
18 }
19
20 int main(){
21 EulerPrime();
22 while(scanf("%d",&n)!=EOF&&n!=0){
23 i=0,ans=0;
24 while(prime[i]<n/2){
25 if(check[n-prime[i]]==0)ans++;
26 i++;
27 }
28 printf("%d
",ans);
29 }
30 return 0;
31 }