Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find prime number c++

#include <math.h>
// time: O(sqrt(n)) ..  space: O(1)
bool isPrime(int n) {
  if (n < 2) return false;
  int iter = 2;
  while(iter <= sqrt(n)) {
  	if (n % iter == 0) return false;
    iter++;
  }
  return true;
}
Source by codejudge.blogspot.com #
 
PREVIOUS NEXT
Tagged: #find #prime #number
ADD COMMENT
Topic
Name
3+4 =