UVA 543 - Goldbach's Conjecture

Problem PDF

Solution:

/*************************************
******** Team : BUBT_HIDDEN **********
**************************************
*********** Shipu Ahamed *************
*************************************/

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define ll long long
#define sc scanf
#define pf printf
#define pi 2*acos(0.0)

#define ft first
#define se second
#define st(s) s.size();
#define r(input) freopen("input.txt","r",stdin)
#define w(output) freopen("output.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define un(v) Sort(v), v.erase(unique(v.begin(),v.end()),v.end())
#define cover(a,d) memset(a,d,sizeof(a))
using namespace std;

bool prime[10000010];
void sieve()
{
    cover(prime,true);
    prime[1]=false;
        int n=sqrt(10000000);
        for(int i=2;i<=n;i++)
        {
            if(prime[i]!=false)
            {
                for(int j=2*i;j<=10000000;j=j+i)
                {
                    prime[j]=false;
                }
            }
        }
}
int main()
{
    sieve();
    int n;
    while(sc("%d",&n)==1)
    {
        if(n==0) break;
        int a,i;
        for(i=2;i<1000000;i++)
        {
            if(prime[i])
            {
                a=n-i;
                if(prime[a])
                 break;
            }
        }
        pf("%d = %d + %d\n",n,i,a);

    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/543/543.cpp