#include #include int main(){ int M, N; scanf("%d %d", &M, &N); int g = std::__gcd(M, N); M = M / g; N = N / g; int t = 0; while(M % N > 0){ t += 1 + M / N; int nm = N, nn = M % N; M = nm; N = nn; } t += M / N - 1; printf("%d\n", t); }