import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.numeric; // gcd void main() { auto rd = readln.split.to!(int[]), m = rd[0], n = rd[1]; auto g = gcd(m, n); m /= g; n /= g; auto r = 0; for (; m > 1 || n > 1; ++r) { if (m > n) m -= n; else swap(m, n); } writeln(r); }