fork(3) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<int> ilist;
  7.  
  8.  
  9. int diophantine(int n, int i)
  10. {
  11. int nret=ilist.empty() ? 0 : ilist.back() -1;
  12.  
  13. if (n==0)
  14. {
  15. size_t x;
  16. for (x=0; x < ilist.size(); x++) cout << " " << ilist[x];
  17. cout << endl;
  18. ilist.pop_back();
  19. }
  20. else if (i>0)
  21. {
  22. ilist.push_back(i);
  23. diophantine(n, diophantine(n-i, n-i));
  24. if (nret > 0) ilist.pop_back();
  25. }
  26.  
  27. return (nret);
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. int n;
  34. cin >> n;
  35.  
  36. if (n > 0)
  37. {
  38. diophantine(n, n);
  39. }
  40. else cout << "usage: prog <Z+>" << endl;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 2860KB
stdin
7
stdout
 7
 6 1
 5 2
 5 1 1
 4 3
 4 2 1
 4 1 2
 4 1 1 1
 3 4
 3 3 1
 3 2 2
 3 2 1 1
 3 1 3
 3 1 2 1
 3 1 1 2
 3 1 1 1 1
 2 5
 2 4 1
 2 3 2
 2 3 1 1
 2 2 3
 2 2 2 1
 2 2 1 2
 2 2 1 1 1
 2 1 4
 2 1 3 1
 2 1 2 2
 2 1 2 1 1
 2 1 1 3
 2 1 1 2 1
 2 1 1 1 2
 2 1 1 1 1 1
 1 6
 1 5 1
 1 4 2
 1 4 1 1
 1 3 3
 1 3 2 1
 1 3 1 2
 1 3 1 1 1
 1 2 4
 1 2 3 1
 1 2 2 2
 1 2 2 1 1
 1 2 1 3
 1 2 1 2 1
 1 2 1 1 2
 1 2 1 1 1 1
 1 1 5
 1 1 4 1
 1 1 3 2
 1 1 3 1 1
 1 1 2 3
 1 1 2 2 1
 1 1 2 1 2
 1 1 2 1 1 1
 1 1 1 4
 1 1 1 3 1
 1 1 1 2 2
 1 1 1 2 1 1
 1 1 1 1 3
 1 1 1 1 2 1
 1 1 1 1 1 2
 1 1 1 1 1 1 1