use std::io::Read; fn get_word() -> String { let stdin = std::io::stdin(); let mut stdin=stdin.lock(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec = Vec::with_capacity(16); loop { let res = stdin.read(&mut u8b); if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = String::from_utf8(buf).unwrap(); return ret; } } } #[allow(dead_code)] fn get() -> T { get_word().parse().ok().unwrap() } fn squmul(a: &[Vec], b: &[Vec], mo: i64) -> Vec> { let n = a.len(); let mut ret = vec![vec![0; n]; n]; for i in 0..n { for j in 0..n { for k in 0..n { ret[i][k] += a[i][j] * b[j][k]; ret[i][k] %= mo; } } } ret } fn squpow(a: &[Vec], mut e: i64, mo: i64) -> Vec> { let n = a.len(); let mut sum = vec![vec![0; n]; n]; for i in 0..n { sum[i][i] = 1; } let mut cur = a.to_vec(); while e > 0 { if e % 2 == 1 { sum = squmul(&sum, &cur, mo); } cur = squmul(&cur, &cur, mo); e /= 2; } sum } const MOD: i64 = 998_244_353; fn solve() { let n: i64 = get(); let k: usize = get(); let mut mat = vec![vec![0; 2 * k * k]; 2 * k * k]; for a in 0..k { for b in 0..k { for c in 0..k { if c == a { continue; } if (a > b && b < c) || (a < b && b > c) { mat[b * k + c][a * k + b] += 1; mat[k * k + b * k + c][k * k + a * k + b] += 1; mat[b * k + c][k * k + a * k + b] += a as i64; } } } } let pw = squpow(&mat, n - 2, MOD); let mut ans1 = 0; let mut ans2 = 0; for a in 0..k { for b in 0..k { if a != b { for c in 0..k { for d in 0..k { if c != d { ans1 = (ans1 + pw[a * k + b][c * k + d]) % MOD; ans2 = (ans2 + pw[a * k + b][k * k + c * k + d]) % MOD; ans2 = (ans2 + pw[a * k + b][c * k + d] * (a + b) as i64) % MOD; } } } } } } println!("{} {}", ans1, ans2); } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }