const MOD: usize = 1000000007; fn main() { let (n, p) = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), ) }; let mut fac1 = vec![1]; let mut fac2 = vec![1]; for i in 1..=n { fac1.push(i * fac1[i - 1] % MOD); fac2.push(i * fac2[i - 1] % (MOD - 1)); } let ans = legendre_formula(n, p) * pow_mod(fac1[n], fac2[n], MOD) % MOD; println!("{}", ans); } /// Calculate the exponent of `p` when prime factorizing `n!`. pub fn legendre_formula(n: usize, p: usize) -> usize { let mut n = n; let mut ret = 0; while n != 0 { ret += n / p; n /= p; } ret } /// Calculate the remainder of `exp` power of `base` divided by `m`. pub fn pow_mod(base: usize, exp: usize, m: usize) -> usize { let mut ret = 1 % m; let mut mul = base % m; let mut t = exp; while t != 0 { if t & 1 == 1 { ret = ret * mul % m; } mul = mul * mul % m; t >>= 1; } ret }