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.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5288KB
stdin
27
stdout
1
27
3
9