Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

check prime cpp gfg

bool isPrime(int s){
   if(s <= 1) return false;
   if(s == 2) return true;
   for(int i = 2; i * i <= s; i++) {
       if(s % i== 0) return false;
   }
   return true;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to delete a node c++ 
Cpp :: new float array c++ 
Cpp :: Find minimum maximum element CPP 
Cpp :: C++ fill string with random uppercase letters 
Cpp :: c++ 14 for sublime windoes build system 
Cpp :: gettimeofday header file 
Cpp :: how to calculate bitwise xor c++ 
Cpp :: find in vector 
Cpp :: letter occurrence in string c++ 
Cpp :: convert integer to string in c++ 
Cpp :: struct c++ 
Cpp :: c++ vector remove all duplicate elements 
Cpp :: c++ output current timestamp 
Cpp :: c++ lettura file 
Cpp :: cin exceptions c++ 
Cpp :: c++ for loop multiple variables 
Cpp :: vector of vectors of pairs c++ 
Cpp :: two elements with difference K in c++ 
Cpp :: convert all strings in vector to lowercase or uppercase c++ 
Cpp :: lambda function in c++ 
Cpp :: c++ insert variable into string 
Cpp :: put text on oled 
Cpp :: how to make a vector in c++ 
Cpp :: resharper fold statement 
Cpp :: c++ recorrer string 
Cpp :: even and odd in c++ 
Cpp :: c++ program to convert fahrenheit to celsius 
Cpp :: cpp malloc 
Cpp :: size of unordered_set 
Cpp :: C++, binary search recursive 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =