#include <bits/stdc++.h>
using namespace std;
long long vu[200010], pr[200010], vi[200010], ct, n, k, m[200010], c[200010];
void init() {
  vu[1] = 1;
  for (long long i = 2; i < 200010; i++) {
    if (!vi[i]) {
      pr[++ct] = i;
      vu[i] = -1;
    }
    for (long long j = 1; j <= ct && i * pr[j] < 200010; j++) {
      vi[i * pr[j]] = 1;
      if (i % pr[j] == 0) break;
      vu[i * pr[j]] = -vu[i];
    }
  }
}
long long qp(long long x, long long y) {
  long long r = 1;
  for (; y; y >>= 1, x = x * x % 1000000007ll)
    if (y & 1) r = r * x % 1000000007ll;
  return r;
}
signed main() {
  cin >> n >> k;
  init();
  m[0] = 1;
  long long r = 0;
  for (long long i = 1; i <= n; i++) m[i] = m[i - 1] * k % 1000000007ll;
  for (long long d = 1; d < n; d++) {
    long long l = (2 * n - 2) / d;
    for (long long t = 1; t <= l; t++)
      for (long long s = t; s <= l; s += t)
        c[s] = (c[s] + vu[t] * (min(s - 1, (n - 1) / d) / t -
                                max(0ll, (s * d - n) / d) / t)) %
               1000000007ll;
    for (long long s = 1; s <= l; s++)
      r = (r + m[max(s * d - n, d)] * c[s] % 1000000007ll) % 1000000007ll;
    for (long long i = 0; i < l + 5; i++) c[i] = 0;
  }
  r = r * (qp(qp(k, n), 1000000007ll - 2)) % 1000000007ll;
  cout << r;
}
