require 'mathn'

class Integer
  def lcm(other)
    pf1 = self.prime_division.flatten
    pf2 = other.prime_division.flatten
    h1 = Hash[*pf1]
    h2 = Hash[*pf2]
    hash = h2.merge(h1) {|key,old,new| [old,new].max }
    Integer.from_prime_division(hash.to_a)
  end
end

p 15.lcm(150)     # 150
p 2.lcm(3)        # 6
p 4.lcm(12)       # 12
p 200.lcm(30)     # 600

