find number is prime or not in most optimised way (used in T prime)

PHOTO EMBED

Fri Aug 20 2021 11:15:26 GMT+0000 (UTC)

Saved by @faisals

 
//utility fn to find number is prime or not in most optimised way
 
bool isPrime(int n){
    if(n<=1){
        return false;
    }
    if(n<=3){
        return true;
    }
    if(n%2==0 || n%3==0){
        return false;
    }
 
    for(int i=5;i*i<=n;i+=6){
 
        if(n%i==0 || n%(i+2)==0){
            return false;
        }
 
    }
    return true;
}
content_copyCOPY

http://codeforces.com/contest/230/submission/112224422