fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. ArrayList<Integer> ans=new ArrayList<>();
  15. int n=sc.nextInt();
  16. for(int i=1;i*i<=n;i++){
  17. if(n%i==0){
  18. if(n/i==i){
  19. ans.add(i);
  20. }
  21. else{
  22. ans.add(i);
  23. ans.add(n/i);
  24. }
  25. }
  26. }
  27. for(int i=0;i<ans.size();i++){
  28. System.out.print(ans.get(i)+" ");
  29. }
  30. }
  31. }
Success #stdin #stdout 0.14s 21748KB
stdin
10
stdout
1 10 2 5