#include #include // #include using namespace std; // using namespace atcoder; // using mint = modint998244353; #define i64 int_fast64_t const i64 INF = INT64_MAX; const i64 ERR = INT64_MIN; const i64 MOD = 1000000007; // 切り上げ i64 ceil_devide(i64 x, i64 y) { return (x + y - 1) / y; } // 切り捨て i64 floor_devide(i64 x, i64 y) { return x / y; } i64 sum_linear(i64 n) { return n * (n+1) / 2; } int main() { i64 n,p; cin >> n >> p; i64 p_num = 0; i64 res = 0; for (size_t i = 1; true; i++) { i64 add = n / pow(p, i); if (add < 1) { break; } res += n / pow(p, i); } i64 kaizyou = 1; for (size_t i = 1; i <= n; i++) { kaizyou *= i; kaizyou %= MOD; } for (size_t i = 0; i < kaizyou; i++) { res *= kaizyou; res %= MOD; } cout << res << endl; return 0; }