#include <bits/stdc++.h>
using namespace std;
const int maxn = 400010, mod = 1e9 + 7;
long long n, k, ans, miu[maxn], pri[maxn], cnt, v[maxn], pk[maxn];
long long Power(long long x, long long p) {
  long long res = 1;
  for (; p; p >>= 1, x = x * x % mod)
    if (p & 1) res = res * x % mod;
  return res;
}
int main() {
  scanf("%lld%lld", &n, &k);
  k = Power(k, mod - 2);
  miu[1] = 1;
  v[1] = 1;
  for (int i(2), i_ORZ(n); i <= i_ORZ; i++) {
    if (!v[i]) pri[++cnt] = i, miu[i] = -1;
    for (int j = 1; j <= cnt && i * pri[j] <= n; j++) {
      v[i * pri[j]] = 1;
      if (i % pri[j])
        miu[i * pri[j]] = -miu[i];
      else
        miu[i * pri[j]] = 0;
    }
  }
  for (int i(0), i_ORZ(n * 2); i <= i_ORZ; i++) pk[i] = Power(k, i);
  for (int d(1), d_ORZ(n - 1); d <= d_ORZ; d++)
    for (int t(1), t_ORZ((n * 2 - 2) / d); t <= t_ORZ; t++)
      for (long long s = t * d; s <= n * 2 - 2; s += t * d) {
        if (s == d) continue;
        long long tmp =
            miu[t] * (min(n - 1, s - 1) / d / t - max(0ll, s - n) / d / t);
        ans = (ans + tmp * pk[k, n - max(1ll * d, s - n)] % mod + mod) % mod;
      }
  printf("%lld\n", ans);
  return 0;
}
