#include #include #include #include int ri() { int n; scanf("%d", &n); return n; } #define MOD 1000000007 int main() { int n, k; scanf("%d%d", &n, &k); assert(1 <= k && k <= n && n <= 1000000); static int fact[1000001]; fact[0] = 1; for (int i = 1; i <= 1000000; i++) fact[i] = (int64_t) fact[i - 1] * i % MOD; int cur = fact[1000000]; static int inv[1000001]; inv[1000000] = 1; for (int i = 0; i < 30; i++) { if ((MOD - 2) >> i & 1) inv[1000000] = (int64_t) inv[1000000] * cur % MOD; cur = (int64_t) cur * cur % MOD; } for (int i = 1000000; i--; ) inv[i] = (int64_t) inv[i + 1] * (i + 1) % MOD; int a = n, b = k; while (a && b) { if (a > b) a %= b; else b %= a; } int p[20], n_p = 0, t = a + b; for (int i = 2; i < t; i++) if (t % i == 0) { p[n_p++] = i; while (t % i == 0) t /= i; } if (t > 1) p[n_p++] = t; int res = 0; for (int i = 1; i < 1 << n_p; i++) { int cur = 1; for (int j = 0; j < n_p; j++) if (i >> j & 1) cur *= p[j]; int add = (int64_t) fact[n / cur] * inv[k / cur] % MOD * inv[(n - k) / cur] % MOD; if (__builtin_popcount(i) & 1) res = (res + add) % MOD; else res = (res - add + MOD) % MOD; } printf("%d\n", res); return 0; }