Answers for "efficient prime number checking algorithm"

C#
1

prime number checking algorithm

function isPrime(num) {
  if (num <= 3) return num > 1;
  
  if ((num % 2 === 0) || (num % 3 === 0)) return false;
  
  let count = 5;
  
  while (Math.pow(count, 2) <= num) {
    if (num % count === 0 || num % (count + 2) === 0) return false;
    
    count += 6;
  }
  
  return true;
}
Posted by: Guest on August-13-2021
0

prime number checking algorithm

def is_prime(n: int) -> bool:
    """Primality test using 6k+-1 optimization."""
    if n <= 3:
        return n > 1
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i ** 2 <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True
Posted by: Guest on June-02-2021

Code answers related to "efficient prime number checking algorithm"

C# Answers by Framework

Browse Popular Code Answers by Language