#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 100000009
int arr[MAX];
void sieve()
{
long long int i,j,k;
k=sqrt(MAX);
for(i=3; i<=k; i+=2)
{
if(arr[i]==0)
{
for(j=i*i; j<MAX; j+=i+i)
{
arr[j]=1;
}
}
}
arr[1]=1;
for(i=4; i<MAX; i=i+2)
{
arr[i]=1;
}
}
int main()
{
long long int a,b,c,d,k,n;
sieve();
while(scanf("%lld",&n)==1)
{
if(n<=4)
{
printf("%lld is not the sum of two primes!\n",n);
continue;
}
if(n%2==1)
{
d=n-2;
if(arr[d]!=1)
{
printf("%lld is the sum of 2 and %lld.\n",n,d);
continue;
}
else
{
printf("%lld is not the sum of two primes!\n",n);
continue;
}
}
c=n/2;
if(c%2==0)
{
c=c-1;
}
a=1;
for(k=c; k>=1; k=k-2)
{
b=n-k;
if(b-k>0 && arr[b]!=1 && arr[k]!=1)
{
a=0;
break;
}
}
if(a==0)
{
printf("%lld is the sum of %lld and %lld.\n",n,k,b);
}
else
{
printf("%lld is not the sum of two primes!\n",n);
}
}
return 0;
}
#include<string.h>
#include<math.h>
#define MAX 100000009
int arr[MAX];
void sieve()
{
long long int i,j,k;
k=sqrt(MAX);
for(i=3; i<=k; i+=2)
{
if(arr[i]==0)
{
for(j=i*i; j<MAX; j+=i+i)
{
arr[j]=1;
}
}
}
arr[1]=1;
for(i=4; i<MAX; i=i+2)
{
arr[i]=1;
}
}
int main()
{
long long int a,b,c,d,k,n;
sieve();
while(scanf("%lld",&n)==1)
{
if(n<=4)
{
printf("%lld is not the sum of two primes!\n",n);
continue;
}
if(n%2==1)
{
d=n-2;
if(arr[d]!=1)
{
printf("%lld is the sum of 2 and %lld.\n",n,d);
continue;
}
else
{
printf("%lld is not the sum of two primes!\n",n);
continue;
}
}
c=n/2;
if(c%2==0)
{
c=c-1;
}
a=1;
for(k=c; k>=1; k=k-2)
{
b=n-k;
if(b-k>0 && arr[b]!=1 && arr[k]!=1)
{
a=0;
break;
}
}
if(a==0)
{
printf("%lld is the sum of %lld and %lld.\n",n,k,b);
}
else
{
printf("%lld is not the sum of two primes!\n",n);
}
}
return 0;
}
1 comments: (+add yours?)
thanks
Post a Comment