2019-02-18 13:20:35 +01:00
|
|
|
# LCM (Least Common Multiple) of two numbers is the smallest number which can be divided by both numbers.
|
|
|
|
|
2021-02-07 08:05:54 +01:00
|
|
|
p 'Least Common Multiple'
|
2019-02-18 13:20:35 +01:00
|
|
|
|
2021-02-07 08:05:54 +01:00
|
|
|
p 'Enter first number'
|
2019-02-18 13:20:35 +01:00
|
|
|
value_one = gets.chomp.to_i
|
|
|
|
|
2021-02-07 08:05:54 +01:00
|
|
|
p 'Enter second number'
|
2019-02-18 13:20:35 +01:00
|
|
|
value_two = gets.chomp.to_i
|
|
|
|
|
|
|
|
def gcd(first, second)
|
|
|
|
if second != 0
|
2021-02-07 08:05:54 +01:00
|
|
|
gcd(second, first % second)
|
2019-02-18 13:20:35 +01:00
|
|
|
else
|
|
|
|
first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def lcm(first, second)
|
2021-02-07 08:05:54 +01:00
|
|
|
(first * second) / gcd(first, second)
|
2019-02-18 13:20:35 +01:00
|
|
|
end
|
|
|
|
|
2021-02-07 08:05:54 +01:00
|
|
|
p "Least Common Multiple is: #{lcm(value_one, value_two)}"
|