My code is not passing the test case

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();

	if(N>2){
		int i=2;
	    while(i<N){
		    if(N%i==0){
			    System.out.println("Not Prime");
		
		}
		    else {
			    System.out.println("Prime");
		}
		i++;
		}
}
	

}

}

@mishikasrvastava,
You can further optimize your code.

If you think about it then all factors of a number will be less than N/2. There’s a way to further optimize it by going till sqrt(N). Try to find the logic why sqrt(N) will work, if you face any problem, reply on this thread. :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.