require 'prime' A, B = gets.split.map(&:to_i) def gcd(a, b) g = a.gcd(b) return 1 if g == 1 g * gcd(a / g + b / g, g) end puts gcd(A, B)