fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7.  
  8. long long n;
  9. cin >> n;
  10.  
  11. vector<long long> a;
  12. stack<long long> b;
  13.  
  14. for (long long i=1; i*i<=n; i++) {
  15. if (n%i == 0) {
  16. a.push_back(i);
  17. if (i!=n/i) {
  18. b.push(n / i);
  19. }
  20. }
  21. }
  22.  
  23. for (auto d : a) {
  24. cout << d << endl;
  25. }
  26.  
  27. while (!b.empty()) {
  28. cout << b.top() << '\n';
  29. b.pop();
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5324KB
stdin
65536
stdout
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536