Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#gcdlcm

int.gcdlcm(other_int) → array

Returns an array with the greatest common divisor and the least common multiple of the two integers, [gcd, lcm].

Example
36.gcdlcm(60)                  #=> [12, 180]
2.gcdlcm(2)                    #=> [2, 2]
3.gcdlcm(-7)                   #=> [1, 21]
((1<<31)-1).gcdlcm((1<<61)-1)  #=> [1, 4951760154835678088235319297]
See also #gcd #inspect #floor #integer? also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0