#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long int #define ti4 tuple #define pii pair #define REP(x,n) for(int x = 0;x < n;x++) template void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } struct UnionFind { vector data; UnionFind(int size) : data(size, -1) { } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; const ll mod = (ll)(1e9+7); struct SimpleHash { size_t operator()(const std::pair& p) const { return p.first * mod + p.second; } }; int main() { ll n, d; cin >> n >> d; ll front = 0; ll c = 0; if(d > n) { d = d % n; } if(d == 0) { cout << 0 << endl; return 0; } if(n == d) { cout << 0 << endl; return 0; } while(true) { ll rest = (n-front) % d; c += (n-front) / d; if(rest == 0) { break; } front = - rest; } cout << c-1 << endl; return 0; }