#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef bitset<16> BS; const ll MOD = 1E+09 + 7; const ll INF = 1E15; const int MAX_N = 1E+05; ll N, D; ll gcd(ll a, ll b); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> D; ll d = gcd(N, D); /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ cout << N / d - 1 << "\n"; return 0; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }