Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- // write your code here
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] list = new int[n];
- int[] binary = new int[n];
- for (int i = 0; i <n ; i++) {
- binary [i]=1;
- list[i]=i+1;
- if(list[i]%2==0 && list[i]>2){
- binary[i]=0;
- }
- }// filling list with integers till n & binary with 0 for all even numbers
- for (int j = 3; j*j<=n ; j+=2) {
- if(n%list[j]==0){binary[j]=0;
- }
- }
- //System.out.println(Arrays.toString(binary)); check the values saved in binary
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement