algorithms.arithmetic

GCD

Greatest common divisor (gcd) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers.

gcd(*integer_nums: int) → int[source]

Function for calculating GCD [greatest common divisor] of N integers

Parameters:*integer_nums – integer arguments
Returns:Greatest common divisor of N positive integers

Examples

>>> gcd(54, 24)
6
>>> gcd(2, 4, 6, 8, 16)
2

LCM

The least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b. [Wikipedia]

lcm(*integer_nums: int) → int[source]

Private function for calculating LCM [least common multiple] of N integers

Parameters:*integer_nums – integer arguments
Returns:Least common multiple of N positive integers.

Examples

>>> lcm(16, 20)
80
>>> lcm(8, 9, 21)
504