fork download
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5. int main() {
  6. // Input
  7. int n; cin >> n;
  8. set<int> se;
  9.  
  10. // Process -> Output
  11. for (int i = 1; i*i <= n; ++i) {
  12. if (n % i == 0) {
  13. se.insert(i);
  14. if (i != n/i)
  15. se.insert(n/i);
  16. }
  17. }
  18. for (int x: se) cout << x << ' ';
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 5312KB
stdin
16
stdout
1 2 4 8 16