gets a,*b=gets.split.map(&:to_i) b=b.inject(:*) gets *c,d=gets.split.map(&:to_i) c=c.inject(:*) a*=d b*=c g=a.gcd(b) puts"#{a/g} #{b/g}"