Answers for "fast way to check if a number is prime C++"

C++
0

fast way to check if a number is prime C++

//O(sqrt(n))
bool isPrime(int num){
    if(num <= 1) return false;
    for(int i = 2; i <= sqrt(num); i++){
          if(num % i == 0) return false;
    }
    return true;
}
Posted by: Guest on September-17-2021

Code answers related to "fast way to check if a number is prime C++"

Browse Popular Code Answers by Language