Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions prometheus/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def gcd(a: int, b: int) -> int:
"""
Euclidean algorithm to find the greatest common divisor of two numbers.

:param a: The first integer.
:param b: The second integer.
:return: The greatest common divisor of a and b.
"""
while b:
a, b = b, a % b
return abs(a)


def lcm(a: int, b: int) -> int:
"""
Calculate the least common multiple of two numbers using the formula: lcm(a, b) = |a*b| / gcd(a, b).

:param a: The first integer.
:param b: The second integer.
:return: The least common multiple of a and b.
"""
return abs(a * b) // gcd(a, b)