fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool check(int n){
  4. if(n < 2) return false;
  5. for(int i = 2; i <= sqrt(n);++i){
  6. if(n % i == 0) return false;
  7. }
  8. return true;
  9. }
  10. int main(){
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. int n;
  14. cin >> n;
  15. if(check(n) == true){
  16. cout <<"1\n"<<n;
  17. return 0;
  18. }
  19. for(int i = n - 1; i >= 2;--i){
  20. if(check(i) == true){
  21. if(check(n-i) == true){
  22. cout <<"2\n"<<i <<" "<<n-i;
  23. return 0;
  24. }else{
  25. for(int j = 2; j < n- i;++j){
  26. if(check(j) == true && check(n-i-j) == true){
  27. cout <<"3\n"<<i <<" "<<j<<" " <<n-i-j;
  28. return 0;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
2
21841 7