UVa 543 - Goldbach's Conjecture

#include<stdio.h>
#include<math.h>
int main()
{
    int n,i,j,l,c,flag,t,d,in;
    while(scanf("%d",&n)==1 && n!=0)
    {
        l=0,flag=0,in=0;
        t=n;
        if(t%2==0)
            t--;
        for(i=t; i>=3; i-=2)
        {
            c=0;
            for(j=3; j<=sqrt(i); j+=2)
            {
                if(i%j==0)
                {
                    c=1;
                    break;
                }
            }
            if(c==0)
            {
                d=n-i;
                if(d%2==0 || d==1)
                    continue;
                in=0;
                for(j=3; j<=sqrt(d); j+=2)
                {
                    if(d%j==0)
                    {
                        in++;
                        break;
                    }
                }
                if(in==0)
                {
                    flag++;
                    printf("%d = %d + %d\n",n,d,i);
                    break;
                }
            }
        }
        if(flag==0)
            printf("Goldbach's conjecture is wrong.\n");
 
    }
    return 0;
}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 মন্তব্য(গুলি):

একটি মন্তব্য পোস্ট করুন