Mathematics
Algorithms
Logic
Numbers
function prime_checker (n) { if ([0,1].includes(n)) return false; if (n == 2) return true; if (n % 2 == 0) return false; for(let i = 3; i < n; i += 2) { if(n % i === 0) return false; } return true; }
- function prime_checker (n) {
- if ([0,1].includes(n)) return false;
for(let i = 2; i < n; i++) {- if (n == 2) return true;
- if (n % 2 == 0) return false;
- for(let i = 3; i < n; i += 2) {
- if(n % i === 0) return false;
- }
- return true;
- }
Mathematics
Algorithms
Logic
Numbers
def prime_checker(n): if n == 2: return True if n < 2 or n % 2 == 0: return False for i in range(3, n, 2): if n % i == 0: return False return True
- def prime_checker(n):
a = 0for i in range(2,n):if n == 2:return Trueelif n%i == 0:return False- if n == 2: return True
- if n < 2 or n % 2 == 0: return False
- for i in range(3, n, 2):
- if n % i == 0: return False
- return True
Mathematics
Algorithms
Logic
Numbers