#include <bits/stdc++.h>
using namespace std;
using INT = long long;
vector<int> res[201000];
int w[201000];
int cnt[201000];
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < 201000; i++) {
    for (int j = i; j < 201000; j += i) res[j].push_back(i);
  }
  w[1] = 1, cnt[1] = 0;
  for (int i = 2; i < 201000; i++) {
    int p = res[i][1];
    if (i / p % p == 0)
      w[i] = w[i / p];
    else
      w[i] = w[i / p] * p;
    if (w[i] == i) cnt[i] = cnt[i / p] + 1;
  }
  int ans = 0;
  for (int x = 2; x < 2 * n - 1; x++) {
    for (int d : res[x]) {
      if (d >= n) break;
      int L = max(1, (x - n + d) / d), R = (min(n, x) - 1) / d;
      INT tot = 0;
      for (int v : res[w[x / d]]) {
        if (cnt[v] & 1)
          tot -= R / v - (L - 1) / v;
        else
          tot += R / v - (L - 1) / v;
      }
      tot %= 1000000007;
      ans += tot * power(k, max(x - n, d), 1000000007) % 1000000007;
      ans %= 1000000007;
    }
  }
  ans = (INT)ans * power(power(k, n, 1000000007), 1000000007 - 2, 1000000007) %
        1000000007;
  cout << ans << endl;
}
