Topic: Mathematical
Questions Successfully Completed: 1
1) Primality Test | Easy |
Primality Test
Question
Input: N = 5 Output: Yes Explanation: 5 is only divisible by 1 and itself. So, 5 is a prime number.
public boolean isPrime(int N) {
if(N==1){return false;}
int count = 0;
int k = (int)Math.sqrt(N);
for(int i=2;i<=k;i++){
if(N%i==0){
count =1;
break;
}
}
if(count==1){return false;}
else{return true;}
}
Thank you for reading :)