fork download
  1. #include <iostream>
  2. using namespace std;
  3. #define ll long long int
  4.  
  5. void factors(int n){
  6. for(int i=1;i*i<=n;i++){
  7. if(n%i==0){
  8. cout<<i<<" ";
  9. if(n/i != i)cout<<n/i<<" ";
  10. }
  11. }
  12. }
  13.  
  14. int main() {
  15. int n;
  16. cin>>n;
  17. cout<<"Factors of "<<n<<" : "<<endl;
  18. factors(n);
  19. return 0;
  20. }
Success #stdin #stdout 0s 5284KB
stdin
20
stdout
Factors of 20 : 
1 20 2 10 4 5