fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<int> path;
  7.  
  8. void OutputRec(int max, int value)
  9. {
  10. if (value == 1) {
  11. for (int i = 0; i < path.size(); i++) cout << path[i] << " ";
  12. if (path.size() == 1) cout << "1";
  13. cout << endl;
  14. return;
  15. }
  16.  
  17. for (int i = max; i > 1; i--)
  18. {
  19. if (value % i == 0) {
  20. path.push_back(i);
  21. OutputRec(i, value / i);
  22. path.pop_back();
  23. }
  24. }
  25. }
  26.  
  27. void Output(int value)
  28. {
  29. cout << "Result for " << value << ": " << endl;
  30. path = vector<int>();
  31. OutputRec(value, value);
  32. }
  33.  
  34. int main() {
  35. Output(4);
  36. Output(16);
  37. Output(36);
  38. Output(256);
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Result for 4: 
4 1
2 2 
Result for 16: 
16 1
8 2 
4 4 
4 2 2 
2 2 2 2 
Result for 36: 
36 1
18 2 
12 3 
9 4 
9 2 2 
6 6 
6 3 2 
4 3 3 
3 3 2 2 
Result for 256: 
256 1
128 2 
64 4 
64 2 2 
32 8 
32 4 2 
32 2 2 2 
16 16 
16 8 2 
16 4 4 
16 4 2 2 
16 2 2 2 2 
8 8 4 
8 8 2 2 
8 4 4 2 
8 4 2 2 2 
8 2 2 2 2 2 
4 4 4 4 
4 4 4 2 2 
4 4 2 2 2 2 
4 2 2 2 2 2 2 
2 2 2 2 2 2 2 2