Ruby 2.7.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Integerクラス > gcd
gcd(n) -> Integer
[permalink][rdoc]自身と整数 n の最大公約数を返します。
2.gcd(2) # => 2
3.gcd(7) # => 1
3.gcd(-7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
また、self や n が 0 だった場合は、0 ではない方の整数の絶対値を返します。
3.gcd(0) # => 3
0.gcd(-7) # => 7
[SEE_ALSO] Integer#lcm, Integer#gcdlcm