示例#1
0
 /**
  * @dataProvider dataProviderForGCD
  */
 public function testGCD(int $a, int $b, int $gcd, int $_, int $__)
 {
     $this->assertEquals($gcd, Algebra::gcd($a, $b));
 }
示例#2
0
 /**
  * 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);
 }