samedi 25 mai 2019

Why is it showing wrong answer?

Problem: UVA 543 Showing wrong answer

#include<bits/stdc++.h>
using namespace std;
    int a[10000001],i,j,n;
    vector<int> prime;

main()
{


    for(i=2;i<=1000000;i++)
        a[i]=1;
    for(i=2;i<=1000;i++)
    {
        if(a[i])
        {
            for(j=i*i;j<=1000000;j+=i)
                a[j]=0;
        }
    }
    a[0]=a[1]=a[2]=0;
    for(j=3;j<=1000000;j++)
        if(a[j])
        prime.push_back(j);
        int n=-1;
        int flag=1;
        while(n!=0)
        {
            cin>>n;

          for(i=0;prime[i]<=n;i++)
        {
            for(j=0;prime[j]<=n;j++)
                if(prime[i]+prime[j]==n)
                {
                    flag=0;

                        cout<<n<<" = "<<prime[i]<<" + "<<prime[j]<<endl;
                        cin>>n;
                }

        }
        if(flag==1)
            cout<<"'Goldbach's conjecture is wrong.'"<<endl;


        }



}

I supposed to be correct. I can't identify where the problem is. But still showing wrong answer after submission. Can anyone help me t identify the actual problem here? Or is there any logical error ?

Aucun commentaire:

Enregistrer un commentaire