fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <stack>
  4. using namespace std;
  5. int main() {
  6. int n;
  7. cin >> n;
  8. stack < int > div;
  9. const double sqrt_n = sqrt ( n );
  10. for ( int i = 1; i <= sqrt_n; i++ ) {
  11. if ( n % i == 0 ) {
  12. div.push ( i );
  13. cout << i << " ";
  14. }
  15. }
  16. if ( div.top () == sqrt_n ) div.pop();
  17. while ( !div.empty () ) {
  18. cout << n / div.top () << " ";
  19. div.pop ();
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 4508KB
stdin
36
stdout
1 2 3 4 6 9 12 18 36