Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. // write your code here
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7. int[] list = new int[n];
  8. int[] binary = new int[n];
  9.  
  10. for (int i = 0; i <n ; i++) {
  11. binary [i]=1;
  12. list[i]=i+1;
  13. if(list[i]%2==0 && list[i]>2){
  14. binary[i]=0;
  15. }
  16.  
  17.  
  18. }// filling list with integers till n & binary with 0 for all even numbers
  19.  
  20. for (int j = 3; j*j<=n ; j+=2) {
  21. if(n%list[j]==0){binary[j]=0;
  22.  
  23. }
  24.  
  25. }
  26.  
  27.  
  28. //System.out.println(Arrays.toString(binary)); check the values saved in binary
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement