bool isPrime(int number){
if(number < 2) return false;
if(number == 2) return true;
if(number % 2 == 0) return false;
for(int i=3; (i*i)<=number; i+=2){
if(number % i == 0 ) return false;
}
return true;
}
More Related Contents:
- Which is the fastest algorithm to find prime numbers?
- Printing prime numbers from 1 through 100
- Fastest algorithm for primality test [closed]
- Mixing two arrays by alternating elements two by two
- banker’s algorithm in c++
- What is the difference between palindrome permutation and permutation? [closed]
- How to replace all occurrences of a character in string?
- Rotating a point about another point (2D)
- Sorting zipped (locked) containers in C++ using boost or the STL
- std::transform() and toupper(), no matching function
- C++ string::find complexity
- what is the difference between set and unordered_set in C++?
- C++ Efficiently Calculating a Running Median [duplicate]
- Most efficient/elegant way to clip a number?
- The intersection of two sorted arrays
- Finding nearest point in an efficient way
- sine wave that slowly ramps up frequency from f1 to f2 for a given time
- Fast n choose k mod p for large n?
- Inverting a 4×4 matrix
- Print 2-D Array in clockwise expanding spiral from center
- Why would anyone use set instead of unordered_set?
- std::back_inserter for a std::set?
- How to rotate a N x N matrix by 90 degrees? [closed]
- Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? [duplicate]
- Why there is no std::copy_if algorithm?
- LRU implementation in production code
- priority queue with limited space: looking for a good algorithm
- C#: How to make Sieve of Atkin incremental
- How can I test whether a number is a power of 2?
- Checking if all elements of a vector are equal in C++