Skip to content

Commit

Permalink
Update carmichael_number.py
Browse files Browse the repository at this point in the history
Made changes taking into account the addition: 
from maths.greatest_common_divisor import greatest_common_divisor.

Now instead of gcd it is used: greatest_common_divisor.
  • Loading branch information
quant12345 authored Oct 9, 2023
1 parent e0c8084 commit 32bcb81
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions maths/carmichael_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@
https://en.wikipedia.org/wiki/Carmichael_number
"""


def gcd(a: int, b: int) -> int:
"""
Examples:
>>> gcd(9, 3)
3
>>> gcd(2, 1)
1
"""

if a < b:
return gcd(b, a)
if a % b == 0:
return b
return gcd(b, a % b)
from maths.greatest_common_divisor import greatest_common_divisor


def power(x: int, y: int, mod: int) -> int:
Expand Down Expand Up @@ -72,7 +56,7 @@ def is_carmichael_number(n: int) -> bool:

b = 2
while b < n:
if gcd(b, n) == 1 and power(b, n - 1, n) != 1:
if greatest_common_divisor(b, n) == 1 and power(b, n - 1, n) != 1:
return False
b += 1
return True
Expand Down

0 comments on commit 32bcb81

Please sign in to comment.