Advertisement
p32929

UVA - 686

Jun 14th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define N 100000
  4. #define M 50000
  5. char P[N];
  6. int prime[M];
  7. void sieve( );
  8. int main()
  9. {
  10.     sieve();
  11.     int i,j,count=0,n,temp;
  12.     while(scanf("%d",&n)==1)
  13.     {
  14.         if(n==0)
  15.             break;
  16.         temp=n;
  17.         for(i=0; i<=temp/2; i++)
  18.             for(j=0; j<=i; j++)
  19.             {
  20.                 if(prime[i]+prime[j]==n)
  21.                 {
  22.                     count++;
  23.                 }
  24.             }
  25.         printf("%d\n",count);
  26.         count=0;
  27.     }
  28.     return 0;
  29. }
  30. void sieve( )
  31. {
  32.     int i,j,root;
  33.     for(i=0; i<N; i++)
  34.         P[i]=1;
  35.     P[0]=P[1]=0;
  36.     root=sqrt(N);
  37.     for(i=2; i<=root; i++)
  38.         if(P[i]==1)
  39.         {
  40.             for(j=2; i*j<=N; j++)
  41.                 P[i*j]=0;
  42.         }
  43.     j=0;
  44.     for(i=2; i<N && j<M; i++)
  45.     {
  46.         if(P[i]==1)
  47.             prime[j++]=i;
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement