Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > rationalライブラリ > Integerクラス > lcm

instance method Integer#lcm

lcm(n) -> Integer [added by rational]

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

[PARAM] n:
自身との最小公倍数を計算する数

例:

2.lcm(2)                    # => 2
3.lcm(-7)                   # => 21
((1<<31)-1).lcm((1<<61)-1)  # => 4951760154835678088235319297

また、self や n が 0 だった場合は、0 を返します。

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

[SEE_ALSO] Integer#gcd, Integer#gcdlcm

class Integer