fn power(base: usize, times: usize, MOD: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2, MOD); temp * temp % MOD * power(base, times%2, MOD) % MOD } fn fact_inv(size: usize, MOD: usize) -> (Vec, Vec) { let mut facts = vec![0usize; size+1]; let mut fact_invs = vec![0usize; size+1]; let mut invs = vec![0usize; size+1]; facts[0] = 1; facts[1] = 1; fact_invs[0] = 1; fact_invs[1] = 1; invs[1] = 1; for i in 2..=size { facts[i] = facts[i-1] * i % MOD; invs[i] = MOD - invs[MOD % i] * (MOD / i) % MOD; fact_invs[i] = fact_invs[i - 1] * invs[i] % MOD; } (facts, fact_invs) } fn comb(n: usize, r: usize, facts: &Vec, fact_invs: &Vec, MOD: usize) -> usize { facts[n] * fact_invs[r] % MOD * fact_invs[n-r] % MOD } fn main() { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = temp[0]; let MOD = temp[1]; let (facts, fact_invs) = fact_inv(1000, MOD); let mut dp = vec![vec![0usize; n]; n+1]; dp[0][0] = 1; for i in 0..n { for j in 0..=i { dp[i+1][j] += dp[i][j]; dp[i+1][j] %= MOD; for k in 2..=n { if k+j-1 >= n || i+k > n { break; } dp[i+k][j+k-1] += dp[i][j] * comb(n-1-i, k-1, &facts, &fact_invs, MOD) % MOD * power(k, k-2, MOD) % MOD; dp[i+k][j+k-1] %= MOD; } } } for i in 0..n { println!("{}", dp[n][i]); } }