#include <bits/stdc++.h>
using namespace std;
const int N = 100003, mod = 1e9 + 7;
int ksm(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = (long long)a * a % mod)
    if (b & 1) res = (long long)res * a % mod;
  return res;
}
void qmo(int &x) { x += x >> 31 & mod; }
int n, k, a[N << 1], b[N << 1], pw[N], mu[N], pri[N], tot, ans;
bool notp[N];
vector<int> vec[N];
int main() {
  scanf("%d%d", &n, &k);
  notp[0] = notp[1] = true;
  mu[1] = pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = (long long)pw[i - 1] * k % mod;
  for (int i = n; i <= (n - 1 << 1); ++i) a[i] = (n << 1) - i - 1;
  for (int i = 2; i <= n; ++i) {
    if (!notp[i]) {
      pri[tot++] = i;
      mu[i] = mod - 1;
    }
    for (int j = 0; j < tot && i * pri[j] <= n; ++j) {
      notp[i * pri[j]] = true;
      if (i % pri[j])
        mu[i * pri[j]] = mod - mu[i];
      else
        break;
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; j += i) vec[j].emplace_back(i);
  for (int p = 1; p < n; ++p) {
    int l = (n - 1 << 1) / p;
    memset(b + 1, 0, l + 1 << 2);
    for (int d : vec[p]) {
      int m = (n + d - 1) / p;
      qmo(b[m] += mu[p / d] - mod);
      ans = (ans + (m * (m - 1ll) >> 1) % mod * pw[d] % mod * mu[p / d]) % mod;
    }
    for (int i = l - 1; i; --i) qmo(b[i] += b[i + 1] - mod);
    for (int i = 1; i <= l; ++i) qmo(a[i * p] -= b[i] * (i - 1ll) % mod);
  }
  for (int i = n; i <= (n - 1 << 1); ++i)
    ans = (ans + (long long)a[i] * pw[i - n]) % mod;
  printf("%lld\n", (long long)ans * ksm(k, mod - 1 - n) % mod);
}
