fork download
  1. <?php
  2.  
  3. class MathHelper
  4. {
  5. public static function getLeastCommonMultiple($a, $b) {
  6. if (bccomp($a, $b) === 0) return $a;
  7. list($max, $min) = (bccomp($a, $b) == -1) ? [$b, $a] : [$a, $b] ;
  8.  
  9. $lcm = $max;
  10. for ($i = 1; bcmod($lcm, $min) != 0; $i++) {
  11. $lcm = bcmul($max, $i);
  12. }
  13.  
  14. return $lcm;
  15. }
  16. }
  17.  
  18. echo MathHelper::getLeastCommonMultiple('2','100000000000000000000000000000');
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
100000000000000000000000000000