Skip to content

Commit

Permalink
Added the Optimized PrimeChecker Function
Browse files Browse the repository at this point in the history
  • Loading branch information
aashiq-q committed Oct 13, 2024
1 parent db14524 commit b9f31ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 0 additions & 9 deletions Python/Prime Checker

This file was deleted.

13 changes: 13 additions & 0 deletions Python/PrimeChecker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0: # Eliminate even numbers early
return False

# Only check odd numbers starting from 3 up to √n
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True

0 comments on commit b9f31ca

Please sign in to comment.