Codeforces 584D. Dima and Lisa Solution
Solve in C++;
- ///**********ALLAH IS ALMIGHTY************///
- ///AH Tonmoy
- ///Department of CSE,23rd Batch
- ///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- bool isprime(int no)
- {
- int sq=sqrt(no);
- for(int i=2; i<=sq; i++)
- {
- if(no%i==0)
- {
- return false;
- }
- }
- return true;
- }
- main()
- {
- int r,f,i,j,a;
- int n;
- while(scanf("%d",&n)!=EOF)
- {
- f=0;
- if(isprime(n))
- {
- cout<<"1"<<endl;
- cout<<n<<endl;
- }
- else
- {
- for(i=n; i>1; i--)
- {
- if(isprime(i))
- {
- a=i;
- break;
- }
- }
- r=n-a;
- if(r%2==1||r==2)
- {
- cout<<"2"<<endl;
- cout<<r<<" "<<a<<endl;
- }
- else
- {
- for(i=2; i<r-1; i++)
- {
- for(j=r-1; j>1; j--)
- {
- if(isprime(i))
- {
- if(isprime(j))
- {
- if(i+j==r)
- {
- cout<<"3"<<endl;
- cout<<i<<" "<<j<<" "<<a<<endl;
- f=1;
- break;
- }
- if(f==1)
- break;
- }
- if(f==1)
- break;
- }
- if(f==1)
- break;
- }
- if(f==1)
- break;
- }
- }
- }
- }
- }
No comments