Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool isprime(int n)
- {
- int i;
- if(n<2)
- return false;
- for(i=2;i*i<=n;i++)
- {
- if(n%i==0){
- return false;
- }
- }
- return true;
- }
- int main()
- {
- int flag=0,n,i,j,k;
- while(scanf("%d",&n)!=EOF)
- {
- if(n==1)
- {
- printf("%d is not the sum of two primes!\n",n);
- }
- else if(n%2==0)
- {
- flag=0;
- for(j=n/2-1;j>=2;j--)
- {
- if(isprime(j)==true && isprime(n-j)==true)
- {
- printf("%d is the sum of %d and %d.\n",n,j,n-j);
- flag=1;
- break;
- }
- }
- if(flag==0)
- printf("%d is not the sum of two primes!\n",n);
- }
- else
- {
- if(isprime(n-2)==true)
- printf("%d is the sum of 2 and %d.\n",n,n-2);
- else
- printf("%d is not the sum of two primes!\n",n);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement