def f m,n m==n ?0:m%n<1?m/n-1:m>n ?f(m%n,n)+m/n :f(n,m)+1 end p f *gets.split.map(&:to_i)