#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int n, k, mu[N], pw[N];
vector<int> f[N], g[N];
int qpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % mod;
    a = 1ll * a * a % mod, b >>= 1;
  }
  return ret;
}
int C2(int n) {
  if (n < 2) return 0;
  return (1ll * n * (n - 1) / 2) % mod;
}
int main() {
  cin >> n >> k;
  mu[1] = 1;
  for (int i = 1; i < n; i++)
    for (int j = i + i; j < n; j += i) mu[j] -= mu[i];
  pw[0] = 1;
  for (int i = 1; i <= n + n; i++) pw[i] = 1ll * pw[i - 1] * k % mod;
  int inv1 = qpow(pw[n], mod - 2), inv2 = qpow(pw[n + n], mod - 2);
  for (int i = 1; i < n; i++) {
    f[i].push_back(1), g[i].push_back(0);
    for (int j = 1, t = 1; 1ll * i * j < n + n; j++)
      t = 1ll * t * pw[i] % mod, f[i].push_back((f[i].back() + t) % mod),
      g[i].push_back((g[i].back() + 1ll * j * t) % mod);
  }
  int ans = 0;
  for (int d = 1; d < n; d++)
    for (int p = 1; 1ll * p * d < n; p++) {
      int lim = (n - 1) / (p * d), cmp = (n - 1 + d) / (p * d),
          s1 = (1ll * C2(cmp) + (mod - 2ll) * C2(cmp - lim) +
                C2(cmp - 2 * lim)) %
               mod * pw[d] % mod * inv1 % mod;
      int s2 = ((1ll + 2 * lim) * (f[p * d][2 * lim] - f[p * d][cmp] + mod) +
                (mod - 1ll) * (g[p * d][2 * lim] - g[p * d][cmp] + mod)) %
               mod * inv2 % mod;
      ans = (ans + 1ll * (mod + mu[p]) * (s1 + s2)) % mod;
    }
  cout << ans;
  return 0;
}
