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.  
  19. }
  20.  
  21. if(i != n / i){ // avoid duplicate for perfect square
  22. cout << n / i << endl;
  23. }
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5320KB
stdin
27
stdout
1
27
13
3
9
6