/** * @dataProvider dataProviderForFactors */ public function testFactors(int $x, array $factors) { $this->assertEquals($factors, Algebra::factors($x)); }
/** * Least common multiple * The smallest positive integer that is divisible by both a and b. * For example, the LCM of 5 and 2 is 10. * https://en.wikipedia.org/wiki/Least_common_multiple * * |a ⋅ b| * lcm(a, b) = --------- * gcd(a, b) * * @param int $a * @param int $b * * @return int */ public static function lcm(int $a, int $b) : int { // Special case if ($a === 0 || $b === 0) { return 0; } return abs($a * $b) / Algebra::gcd($a, $b); }