#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int u[N], k;
int vis[N], pr[N], cnt, n;
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
long long inv[N];
int main() {
  scanf("%d%d", &n, &k);
  inv[0] = 1;
  inv[1] = pw(k, mod - 2);
  for (int i = 2; i <= n; i++) {
    inv[i] = inv[i - 1] * inv[1] % mod;
  }
  u[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pr[++cnt] = i, u[i] = -1;
    for (int j = 1; j <= cnt && 1LL * pr[j] * i <= n; j++) {
      vis[i * pr[j]] = 1;
      if (i % pr[j]) {
        u[i * pr[j]] = -u[i];
      } else {
        u[i * pr[j]] = 0;
        break;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int s2 = i; s2 <= 2 * n - 1; s2 += i) {
      for (int s = s2; s <= 2 * n - 1; s += s2) {
        long long gcd = s / s2;
        long long l = max(1LL, s2 - (n - 1) / gcd),
                  r = min(s2 - 1LL, (n - 1) / gcd);
        if (l <= r)
          ans += (r / i - (l - 1) / i) * inv[n - max(s - (long long)n, gcd)] %
                 mod * (u[i] + mod) % mod;
        ans %= mod;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
