fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. typedef long long int ll;
  8.  
  9.  
  10. int main() {
  11. int n;
  12. cin>>n;
  13.  
  14. vector<int> ans;
  15.  
  16.  
  17. for(ll i=1;i<=sqrt(n);i++){
  18. if(n%i==0){
  19. if(i==n/i){
  20. ans.push_back(i);
  21. }
  22. else{
  23. ans.push_back(i);
  24. ans.push_back(n/i);
  25.  
  26. }
  27. }
  28. }
  29. sort(ans.begin(),ans.end());
  30.  
  31. for(ll i=0;i<ans.size();i++){
  32. cout<<ans[i]<<" ";
  33.  
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5288KB
stdin
100
stdout
1 2 4 5 10 20 25 50 100