Elementary functions¶
Integer functions of an elementary nature.
- boring_math.number_theory.gcd(m: int, n: int, /) int¶
gcd - greatest common divisor
Uses Euclidean algorithm to compute the gcd of two integers.
- param m:
First int for gcd calculation.
- param n:
Second int for gcd calculation.
- returns:
The gcd of the absolute values of
mandn.
Note
mathematically the
gcd(0, 0)does not existtaking
gcd(0, 0) = 1Better choice than
math.gcd(0, 0) = 0.More mathematically justified.
Eliminates lcm & coprime having to edge case test.
- boring_math.number_theory.lcm(m: int, n: int, /) int¶
lcm - least common multiple
Find the least common multiple (lcm) of two integers.
- param m:
First int for lcm calculation.
- param n:
Second int for lcm calculation.
- returns:
The lcm of the absolute values of
mandn.
- boring_math.number_theory.coprime(m: int, n: int, /) tuple[int, int]¶
coprime
Make 2 integers coprime by dividing out their common factors.
- param m:
First int for coprime calculation.
- param n:
Second int for coprime calculation.
- returns:
The coprime values with original signs, also
(0, 0)whenn = m = 0.