Computer Programming Contest Preparation

ToolBox - Source for: 6/686/t.c



/home/toolbox/public_html/solutions/6/686/t.c
    1 #include<stdio.h>
    2 #include<math.h>
    3 int main()
    4 {
    5     long num,i,j,bin,paici,a,b,p,q,ans;
    6     while(scanf("%ld",&num)==1)
    7         {
    8             if(num==0)    break;
    9             ans=0;
   10             for(i=3; i!=0; i+=2)
   11                 {
   12                     bin=1;
   13                     paici=1;
   14                     a=i;
   15                     b=num-i;
   16                     if(a>b) break;
   17                     if(a%2!=0)
   18                         {
   19                             p=(int)sqrt(a);
   20                             for(j=3; j<=p; j+=2)
   21                                 {
   22                                     if(a%j==0)
   23                                         {
   24                                             bin=0;
   25                                             break;
   26                                         }
   27                                 }
   28                             if(bin==1)
   29                                 {
   30                                     if(b%2!=0)
   31                                         {
   32                                             q=(int)sqrt(b);
   33                                             for(j=3; j<=q; j+=2)
   34                                                 {
   35                                                     if(b%j==0)
   36                                                         {
   37                                                             paici=0;
   38                                                             break;
   39                                                         }
   40                                                 }
   41                                             if(paici==1)
   42                                                 ans=ans+1;
   43                                         }
   44                                 }
   45                         }
   46                 }
   47             if(num==4)
   48                 printf("1\n");
   49             else
   50                 printf("%ld\n",ans);
   51 
   52         }
   53     return 0;
   54 }
   55