Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

prime number c++

bool prime(int x) {
	if (x == 2 || x == 3) return true;
	if (x == 1 || x % 2 == 0 || x % 3 == 0) return false;
	int k = -1;
	while (k<=int(sqrt(x))) {
      	k+=6;
		if (x % k == 0 || x % (k+2) == 0) break;
	}
	return k>int(sqrt(x));
}
Source by codejudge.blogspot.com #
 
PREVIOUS NEXT
Tagged: #prime #number
ADD COMMENT
Topic
Name
7+3 =