fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6.  
  7. int n;
  8. cin>>n;
  9.  
  10. if(n<=0){
  11. cout<<-1<<endl;
  12. }
  13.  
  14.  
  15. for(int i=1; i*i<=n; i++){
  16. if(n%i == 0){
  17. cout<<i<<endl;
  18. if(i != n / i){ // avoid duplicate for perfect square
  19. cout << n / i << endl;
  20. }
  21. }
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 5324KB
stdin
36
stdout
1
36
2
18
3
12
4
9
6