#include <bits/stdc++.h>
using std::max;
using std::vector;
const int MOD = 1e9 + 7;
int sum(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
int mult(int a, int b) { return (a * 1LL * b) % MOD; }
int bin_pow(int a, int n) {
  int res = 1;
  for (; n; n >>= 1, a = mult(a, a))
    if (n & 1) res = mult(res, a);
  return res;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int N = 2e5;
vector<int> cnt[N], divs[N];
int mu[N], sm[N], pw[N];
bool used[N];
int ffunc(int n, int a, int b) {
  int d = gcd(a, b);
  return (d - (n % d)) * max(1, (a + b) / d - (n / d)) +
         (n % d) * max(1, (a + b) / d - (n + d - 1) / d);
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int x = 1; x <= 2 * n; ++x)
    for (int y = x; y <= 2 * n; y += x) divs[y].push_back(x);
  mu[1] = 1;
  for (int x = 1; x <= 2 * n; ++x)
    for (int y = x + x; y <= 2 * n; y += x) mu[y] -= mu[x];
  for (int d = 1; d <= n; ++d) {
    int nn = n / d;
    if (used[nn]) continue;
    cnt[nn].resize(2 * nn + 1);
    for (int s = 2; s <= nn; ++s) {
      for (int x : divs[s]) cnt[nn][s] += mu[x] * (s / x - 1);
      cnt[nn][s] %= MOD;
      sm[nn] = sum(sm[nn], cnt[nn][s]);
    }
    for (int s = nn + 1; s <= 2 * nn; ++s) {
      for (int x : divs[s])
        cnt[nn][s] += mu[x] * max(0, ((nn) / x - (s / x - (nn) / x) + 1));
      cnt[nn][s] %= MOD;
    }
    used[nn] = true;
  }
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = mult(pw[i - 1], k);
  int ans = 0;
  for (int d = 1; d <= n; ++d) {
    ans = sum(ans, mult(sm[n / d], pw[d]));
    ans = sum(ans, mult(cnt[n / d][n / d + 1], pw[d]));
    for (int y = 2; y * d < n; ++y)
      ans = sum(ans, mult(cnt[n / d][n / d + y], pw[y * d - (n % d)]));
  }
  for (int a = 1; a < n; ++a) ans = sub(ans, pw[ffunc(n, a, n)]);
  for (int b = 1; b <= n; ++b) ans = sub(ans, pw[ffunc(n, n, b)]);
  ans = mult(ans, bin_pow(pw[n], MOD - 2));
  printf("%d", ans);
}
