What is wrong in this code?

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner(System.in);
long N=scn.nextLong();
long div=2L;
boolean flag=true;
while(div<=N-1){
if(N%div==0){
flag=false;
}
div++;
}
if(flag==true){
System.out.println(“Prime”);
}
else{
System.out.println(“Not Prime”);
}

}

}

@adityagupta1435,
Your code will give you TLE. See, when you are checking for prime numbers, you needn’t go till N to check if its prime or not prime. You can go till sqrt(N) as well.

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.