Skip to main content
added 1 character in body
Source Link
GorvGoyl
  • 47.2k
  • 37
  • 268
  • 267

this program is much efficient for checking a single number for primality check.

bool check(int n){ if (n <= 3) { return n > 1; } if (n % 2 == 0 || n % 3 == 0) { return false; } int sq=sqrt(n); //include math.h or use i*i<n in for loop for (int i = 5; i<sq;i<=sq; i += 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } 

this program is much efficient for checking a single number for primality check.

bool check(int n){ if (n <= 3) { return n > 1; } if (n % 2 == 0 || n % 3 == 0) { return false; } int sq=sqrt(n); //include math.h or use i*i<n in for loop for (int i = 5; i<sq; i += 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } 

this program is much efficient for checking a single number for primality check.

bool check(int n){ if (n <= 3) { return n > 1; } if (n % 2 == 0 || n % 3 == 0) { return false; } int sq=sqrt(n); //include math.h or use i*i<n in for loop for (int i = 5; i<=sq; i += 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } 
Source Link
GorvGoyl
  • 47.2k
  • 37
  • 268
  • 267

this program is much efficient for checking a single number for primality check.

bool check(int n){ if (n <= 3) { return n > 1; } if (n % 2 == 0 || n % 3 == 0) { return false; } int sq=sqrt(n); //include math.h or use i*i<n in for loop for (int i = 5; i<sq; i += 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; }