#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;
inline void ADD(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
inline void DEC(int& x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
inline int add(int x, int y) { return x + y < MOD ? x + y : x + y - MOD; }
inline int dec(int x, int y) { return x < y ? x - y + MOD : x - y; }
long long q_pow(long long a, long long b, long long p = MOD) {
  long long ret = 1;
  for (; b; a = a * a % p, b >>= 1)
    if (b & 1) ret = ret * a % p;
  return ret;
}
long long q_inv(long long x, long long p = MOD) { return q_pow(x, p - 2, p); }
template <typename T>
void chkmax(T& x, T y) {
  if (y > x) x = y;
}
template <typename T>
void chkmin(T& x, T y) {
  if (y < x) x = y;
}
int N, K;
vector<int> V[MAXN];
int pr[MAXN], pl, np[MAXN], mu[MAXN], pw[MAXN];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; ++i)
    for (int j = i; j <= 2 * N; j += i) V[j].push_back(i);
  mu[1] = 1;
  for (int i = 2; i <= N; ++i) {
    if (!np[i]) {
      pr[++pl] = i, mu[i] = -1;
    }
    for (int j = 1; j <= pl && i * pr[j] <= N; ++j) {
      np[i * pr[j]] = 1;
      if (i % pr[j])
        mu[i * pr[j]] = -mu[i];
      else {
        mu[i * pr[j]] = 0;
        break;
      }
    }
  }
  pw[0] = 1;
  for (int i = 1; i <= N; ++i) pw[i] = 1ll * pw[i - 1] * K % MOD;
  int ans = 0;
  for (int d = 1; d <= N - 1; ++d) {
    int m = (N - 1) / d;
    for (int s = 2; s <= 2 * ((N - 1) / d); ++s) {
      int cur = 0;
      for (int t : V[s]) {
        if (t > m) break;
        if (mu[t]) {
          int tmp;
          if (s / t <= m / t + 1)
            tmp = s / t - 1;
          else if (s / t <= 2 * (m / t))
            tmp = m / t - (s / t - (m / t + 1));
          else
            tmp = 0;
          if (mu[t] == 1)
            ADD(cur, tmp);
          else
            DEC(cur, tmp);
        }
      }
      ADD(ans, 1ll * cur * pw[max(d, d * s - N)] % MOD);
    }
  }
  ans = 1ll * ans * q_inv(pw[N]) % MOD;
  printf("%d", ans);
  return 0;
}
