Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #define N 100000
- #define M 50000
- char P[N];
- int prime[M];
- void sieve( );
- int main()
- {
- sieve();
- int i,j,count=0,n,temp;
- while(scanf("%d",&n)==1)
- {
- if(n==0)
- break;
- temp=n;
- for(i=0; i<=temp/2; i++)
- for(j=0; j<=i; j++)
- {
- if(prime[i]+prime[j]==n)
- {
- count++;
- }
- }
- printf("%d\n",count);
- count=0;
- }
- return 0;
- }
- void sieve( )
- {
- int i,j,root;
- for(i=0; i<N; i++)
- P[i]=1;
- P[0]=P[1]=0;
- root=sqrt(N);
- for(i=2; i<=root; i++)
- if(P[i]==1)
- {
- for(j=2; i*j<=N; j++)
- P[i*j]=0;
- }
- j=0;
- for(i=2; i<N && j<M; i++)
- {
- if(P[i]==1)
- prime[j++]=i;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement