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. int n=sc.nextInt();
  15. Set<Integer> s=new HashSet<>();
  16. for(int i=1;i<=Math.sqrt(n);i++)
  17. {
  18. if(n%i==0)
  19. {
  20. s.add(i);
  21. s.add(n/i);
  22. }
  23. }
  24.  
  25. System.out.println(s);
  26. }
  27. }
Success #stdin #stdout 0.2s 56616KB
stdin
15
stdout
[1, 3, 5, 15]