Fast, easy C++ solution


#1
int Solution::isPrime(int A) {

    if(A<2) return 0;
    if(A==2) return 1;
    if(A%2==0) return 0;                 // If the number is even(>2) it can't be prime.
    for(int i=3; i<=sqrt(A); i=i+2)      // Since the number is not even divide A only by odd.
    {
        if(A%i==0) return 0;
    }
    return 1;
}