Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #fast #check #number #prime
ADD COMMENT
Topic
Name
7+8 =