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. Scanner SC = new Scanner(System.in);
  13. int z = SC.nextInt();
  14.  
  15. System.out.print("1 ");
  16. for(int i=2;i<=z;i++)
  17. {
  18. int c=0;
  19. for(int j=1;j<=i;j++)
  20. {
  21. if(i%j==0)
  22. {
  23. c++;
  24. }
  25. }
  26.  
  27. if(c==2)
  28. {
  29. System.out.printf("%d ",i);
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36. }
  37. }
  38. }
Success #stdin #stdout 0.1s 52988KB
stdin
10
stdout
1 2 3 5 7