#include #include using mint = atcoder::modint998244353; using S6 = std::array; S6 op(S6 x, const S6 &y) { for (int i = 0; i < 6; i++) x[i] = y[x[i]]; return x; } S6 inv(const S6 &x) { S6 y; for (int i = 0; i < 6; i++) y[x[i]] = i; return y; } int index(S6 p) { S6 q = inv(p); int ret = 0; for (int i = 6; i-- > 1;) { ret = ret * (i + 1) + p[i]; int next = p[i], prev = q[i]; p[prev] = next, q[next] = prev; } return ret; } mint solve(const int N, const int K) { if (N == 2) { return 1; } if (N != 6) { mint ret = K; for (int i = 1; i <= N - K; i++) ret *= i; return ret; } const S6 id = {{0, 1, 2, 3, 4, 5}}; // one of the outer automorphisms std::array out; { const std::array adj = {{ {1, 0, 3, 2, 5, 4}, {5, 3, 4, 1, 2, 0}, {3, 2, 1, 0, 5, 4}, {5, 4, 3, 2, 1, 0}, {2, 3, 0, 1, 5, 4}, }}; S6 p = id; do { S6 p_ = p, q = id; for (int i = 0; i < 6; i++) { for (int j = 0; j < 5; j++) { if (p_[j] > p_[j + 1]) { std::swap(p_[j], p_[j + 1]); q = op(q, adj[j]); } } } out[index(p)] = index(q); } while (std::next_permutation(p.begin(), p.end())); } S6 f = id; std::rotate(f.begin(), f.begin() + 1, f.begin() + K); // target[F(f)] must be true std::array target = {}; { S6 p = id; do { bool ok = true; for (int i = 0; i < K; i++) ok &= p[i] == f[i]; target[index(p)] = ok; } while (std::next_permutation(p.begin(), p.end())); } mint ans = 0; { S6 p = id; do { S6 t = op(op(inv(p), f), p); // check inner automorphism if (target[index(t)]) ans += 1; // check outer automorphism if (target[out[index(t)]]) ans += 1; } while (std::next_permutation(p.begin(), p.end())); } return ans; } int main() { int N, K; std::cin >> N >> K; std::cout << solve(N, K).val() << "\n"; return 0; }