#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct mod_int {
  int val;
  mod_int(long long v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = v;
  }
  static int mod_inv(int a, int m = MOD) {
    int g = m, r = a, x = 0, y = 1;
    while (r != 0) {
      int q = g / r;
      g %= r;
      swap(g, r);
      x -= q * y;
      swap(x, y);
    }
    return x < 0 ? x + m : x;
  }
  explicit operator int() const { return val; }
  mod_int &operator+=(const mod_int &other) {
    val += other.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  mod_int &operator-=(const mod_int &other) {
    val -= other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return x % m;
    unsigned x_high = x >> 32, x_low = (unsigned)x;
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  mod_int &operator*=(const mod_int &other) {
    val = fast_mod((uint64_t)val * other.val);
    return *this;
  }
  mod_int &operator/=(const mod_int &other) { return *this *= other.inv(); }
  friend mod_int operator+(const mod_int &a, const mod_int &b) {
    return mod_int(a) += b;
  }
  friend mod_int operator-(const mod_int &a, const mod_int &b) {
    return mod_int(a) -= b;
  }
  friend mod_int operator*(const mod_int &a, const mod_int &b) {
    return mod_int(a) *= b;
  }
  friend mod_int operator/(const mod_int &a, const mod_int &b) {
    return mod_int(a) /= b;
  }
  mod_int &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  mod_int &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  mod_int operator++(int) {
    mod_int before = *this;
    ++*this;
    return before;
  }
  mod_int operator--(int) {
    mod_int before = *this;
    --*this;
    return before;
  }
  mod_int operator-() const { return val == 0 ? 0 : MOD - val; }
  bool operator==(const mod_int &other) const { return val == other.val; }
  bool operator!=(const mod_int &other) const { return val != other.val; }
  mod_int inv() const { return mod_inv(val); }
  mod_int pow(long long p) const {
    assert(p >= 0);
    mod_int a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      a *= a;
      p >>= 1;
    }
    return result;
  }
};
vector<int> smallest_factor;
vector<bool> prime;
vector<int> primes;
void sieve(int maximum) {
  maximum = max(maximum, 2);
  smallest_factor.assign(maximum + 1, 0);
  prime.assign(maximum + 1, true);
  prime[0] = prime[1] = false;
  primes = {};
  for (long long p = 2; p <= maximum; p++)
    if (prime[p]) {
      smallest_factor[p] = p;
      primes.push_back(p);
      for (long long i = p * p; i <= maximum; i += p)
        if (prime[i]) {
          prime[i] = false;
          smallest_factor[i] = p;
        }
    }
}
const int MAX_PRODUCTS = 1024;
int products[MAX_PRODUCTS];
int count_coprime_between(int n, int low, int high) {
  int n_products = 1;
  products[0] = 1;
  while (n > 1) {
    int p = smallest_factor[n];
    do {
      n /= p;
    } while (n % p == 0);
    for (int i = 0; i < n_products; i++)
      products[n_products + i] = products[i] * p;
    n_products *= 2;
  }
  int sum = 0;
  for (int mask = 0; mask < n_products; mask++)
    sum += (__builtin_popcount(mask) % 2 == 0 ? +1 : -1) *
           (high / products[mask] - (low - 1) / products[mask]);
  return sum;
}
int main() {
  int N, K;
  cin >> N >> K;
  sieve(2 * N);
  vector<mod_int> freq(N, 0);
  for (int g = 1; g < N; g++)
    for (int s = 1; s * g <= 2 * (N - 1); s++) {
      int low = max(1, s - (N - 1) / g);
      int high = min((N - 1) / g, s - 1);
      if (low > high) continue;
      freq[N - max(s * g - N, g)] += count_coprime_between(s, low, high);
    }
  mod_int total = 0, pp = 1, inv_K = mod_int(1) / K;
  for (int p = 0; p < N; p++) {
    total += freq[p] * pp;
    pp *= inv_K;
  }
  cout << (int)total << '\n';
}
