Skip to content

Commit

Permalink
added the is_prime function
Browse files Browse the repository at this point in the history
  • Loading branch information
starrytc committed Oct 29, 2024
1 parent 53bd330 commit 1e35635
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions participants/starrytc/pr_tutorial/simple_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ def factorial(value):
return 1
else:
return value * factorial(value - 1)

def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True

0 comments on commit 1e35635

Please sign in to comment.