UVA 10948 The primary problem Solution
Solve in C:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<bits/stdc++.h>
#define M 1000009
using namespace std;
bool marked[M];
vector<int>vec;
void sieve(int n)
{
for(int i=4; i<=n; i+=2)
marked[i]=true;
for(int i=3; i*i<=n; i+=2)
{
if(marked[i]==false)
{
for(int j=i*i; j<=n; j+=i)
{
marked[j]=true;
}
}
}
vec.push_back(2);
for(int i=3; i<=n; i+=2)
{
if(marked[i]==false)
{
vec.push_back(i)
}
}
}
main()
{
int m,r=0,f,i,k=0,t;
sieve(1000009);
while(scanf("%d",&m)==1&&m!=0)
{
int i,j,f=0;
if(m%2==1)
{
t=m-2;
if(marked[t]==true)
k=1;
}
for(i=0; i<(vec.size()); i++)
{
r=(m-vec[i]);
if(marked[r]==false)
{
f=1;
break;
}
if( f==1)
break;
}
cout<<m<<":"<<endl;
if(k==1)
{
cout<<"NO WAY!"<<endl;
k=0;
}
else if( f==1)
{
printf("%d+%d\n",vec[i],r);
k=0;
}
}
}
No comments