Ruby 4.0 リファレンスマニュアル

instance method Integer#lcm

lcm(n) -> Integer[permalink][rdoc][edit]

self と整数 n の最小公倍数を返します。

[EXCEPTION] ArgumentError:
n に整数以外のものを指定すると発生します。
p 2.lcm(2)                  # => 2
p 3.lcm(-7)                 # => 21
p ((1<<31)-1).lcm((1<<61)-1)  # => 4951760154835678088235319297

また、selfn0 だった場合は、0 を返します。

p 3.lcm(0)                  # => 0
p 0.lcm(-7)                 # => 0

[SEE_ALSO] Integer#gcd, Integer#gcdlcm