#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #ifdef __unix__ #include #else #include "bits\stdc++.h" #endif #include #include #include #include #include #define REP(i,a,b) for(i=a;i> M >> N; int a = gcd(M,N); M /= a; N /= a; if(M < N) { swap(M,N); cnt++; } // M >= N while(1) { int a = M/N; if(M%N == 0) a--; cnt += a; M -= a*N; if(M == N) break; swap(M,N); cnt++; } cout << cnt << endl; }