#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   inline long long read() {     long long neg = 1, num = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) neg = -1;     for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ;     return neg * num;   }   long long n, k, tot, f[200010], g[200010], fac[200010], inv[200010],       pri[200010], mu[200010], mul[200010];   bool vis[200010];   inline long long Pow(long long x, long long y) {     long long res = 1;     for (; y; y >>= 1, x = x * x % p)       if (y & 1) res = res * x % p;     return res;   }   inline long long C(long long x, long long y) {     return fac[x] * inv[y] % p * inv[x - y] % p;   }   inline long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   inline void sieve() {     vis[1] = mu[1] = 1;     for (long long i = 2; i <= n; i++) {       if (!vis[i]) pri[++tot] = i, mu[i] = -1;       for (long long j = 1; j <= tot && pri[j] * i <= n; j++) {         vis[i * pri[j]] = 1;         if (i % pri[j] == 0) break;         mu[i * pri[j]] = -mu[i];       }     }     fac[0] = inv[0] = mul[0] = 1;     for (long long i = 1; i <= 2 * n; i++)       fac[i] = fac[i - 1] * i % p, mul[i] = mul[i - 1] * k % p;     inv[2 * n] = Pow(fac[2 * n], p - 2);     for (long long i = 2 * n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % p;     for (long long i = 2; i <= n; i++)       f[i] = (f[i - 1] + (i - 1) * mul[i] % p) % p;     for (long long i = 1; i <= n; i++) g[i] = Pow(f[n / i], i) % p;   }   signed main() {     n = read();     k = read();     sieve();     long long ans = 0, sub = 0;     for (long long i = 2; i <= 2 * n; i++) {       if (i <= n)         ans = (ans + (i - 1) * mul[i] % p) % p;       else         ans = (ans + (2 * n - i + 1) * mul[i] % p) % p;     }     ans = ans * Pow(mul[n], p - 2) % p;     for (long long d = 1; d <= n; d++) {       for (long long T = d; T <= n; T += d) {         long long s1 = (n / T) * (n / T - 1) / 2 % p, s2 = g[T];         if ((n + d - 1) / T != n / T)           s1 = (s1 + (n + d - 1) / T - 1) % p,           s2 = (s2 + ((n + d - 1) / T - 1) * mul[(n + d - 1) / T * T] % p) % p;         ans = (ans + s1 * mul[d] * mu[T / d] % p) % p;         sub = (sub + s2 * mu[T / d]) % p;       }     }     sub = sub * Pow(mul[n], p - 2) % p;     ans = (ans - sub) % p;     for (long long i = 1; i <= n; i++)       ans = (ans - (1 + (i != n)) * mul[max(gcd(i, n), i)]) % p;     ans = ans * Pow(mul[n], p - 2) % p;     ans = (ans % p + p) % p;     printf( %lld n , ans);     return 0;   }   