Core\BigInt::lcm
$bigInt->lcm(Core\BigInt $other): Core\BigInt$bigInt->lcm( Core\BigInt $other, ): Core\BigInt
Returns the least common multiple of this number and another one, as a new Core\BigInt.
The least common multiple is the smallest positive number that both of them divide exactly. Two events that repeat every 4 and every 6 seconds happen together every 12 seconds, and 12 is what lcm returns for 4 and 6.
The result is never negative, and the sign of the two numbers does not change it. The order of the two numbers does not change it either. When one of them is zero the result is 0.
Good to know: the result can be far larger than either number. Two numbers that share no divisor above 1 give their product, so the result can quickly grow too large for an int.
Parameters
$otherCore\BigIntThe other value. If either value is0, the result is0.
Return value
Returns Core\BigInt. A non-negative BigInt.
Examples
The smallest common multiple
<?nvs// Shows the least common multiple of two numbers: the smallest number that// both of them divide exactly.
var $first = Core\BigInt::of(36);var $second = Core\BigInt::of(48);
// 36 and 48 both divide 144, and no smaller positive number. This prints 144.echo $first->lcm($second), "\n";
// The sign of a number and the order of the two do not change the result.// This prints 144 again.echo $second->lcm($first->negated()), "\n";144144When one number is zero
<?nvs// Shows what `lcm` gives when one of the two numbers is zero.
var $value = Core\BigInt::of(42);var $zero = Core\BigInt::of(0);
// Only zero is a multiple of zero, so the result is 0.echo $value->lcm($zero), "\n";
// Two zeroes give 0 as well.echo $zero->lcm($zero), "\n";00When two schedules meet again
<?nvs// Shows when two repeating jobs run at the same moment again. Each period is a// number of microseconds, and the answer is far too large for an `int`.
var $firstJob = Core\BigInt::parse('123456789012345678901');var $secondJob = Core\BigInt::parse('987654321098765432109');
// The two jobs meet after the least common multiple of their periods. This// prints 121932631137021795225845145533336229232209.var $meeting = $firstJob->lcm($secondJob);echo $meeting, "\n";
// Both periods divide that moment exactly, so the remainder is 0 for each of// them. This prints 0 0.echo $meeting->remainder($firstJob), ' ', $meeting->remainder($secondJob), "\n";1219326311370217952258451455333362292322090 0