結果
問題 | No.2747 Permutation Adjacent Sum |
ユーザー | ebi_fly |
提出日時 | 2024-04-20 13:32:30 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 29,062 bytes |
コンパイル時間 | 3,478 ms |
コンパイル使用メモリ | 259,056 KB |
実行使用メモリ | 17,440 KB |
最終ジャッジ日時 | 2024-10-12 09:02:19 |
合計ジャッジ時間 | 16,315 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
ソースコード
#line 2 "math/lagrange_interpolation.hpp" #include <vector> /* reference: https://atcoder.jp/contests/abc208/editorial/2195 verify: https://atcoder.jp/contests/abc208/tasks/abc208_f */ namespace ebi { template <class mint> mint lagrange_interpolation(const std::vector<mint> &f, long long n) { const int d = int(f.size()) - 1; mint fact = 1; std::vector<mint> inv_fact(d + 1); for (int i = 1; i < d + 1; ++i) { fact *= i; } inv_fact[d] = fact.inv(); for (int i = d; i > 0; i--) { inv_fact[i - 1] = inv_fact[i] * i; } std::vector<mint> l(d + 1), r(d + 1); l[0] = 1; for (int i = 0; i < d; ++i) { l[i + 1] = l[i] * (n - i); } r[d] = 1; for (int i = d; i > 0; --i) { r[i - 1] = r[i] * (n - i); } mint res = 0; for (int i = 0; i < d + 1; ++i) { res += mint((d - i) % 2 == 1 ? -1 : 1) * f[i] * l[i] * r[i] * inv_fact[i] * inv_fact[d - i]; } return res; } } // namespace ebi #line 2 "math/linear_sieve.hpp" #line 2 "template/int_alias.hpp" #include <cstdint> namespace ebi { using ld = long double; using std::size_t; using i8 = std::int8_t; using u8 = std::uint8_t; using i16 = std::int16_t; using u16 = std::uint16_t; using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = std::int64_t; using u64 = std::uint64_t; using i128 = __int128_t; using u128 = __uint128_t; } // namespace ebi #line 4 "math/linear_sieve.hpp" /* reference: https://37zigen.com/linear-sieve/ verify: https://atcoder.jp/contests/abc162/submissions/25095562 */ #include <cassert> #line 12 "math/linear_sieve.hpp" namespace ebi { struct linear_sieve { private: using u64 = std::uint64_t; int n; std::vector<int> sieve; std::vector<int> prime; public: linear_sieve(int _n) : n(_n), sieve(std::vector<int>(_n + 1, -1)) { for (int i = 2; i <= n; i++) { if (sieve[i] < 0) { sieve[i] = i; prime.emplace_back(i); } for (auto p : prime) { if (u64(p) * u64(i) > u64(n) || p > sieve[i]) break; sieve[p * i] = p; } } } std::vector<int> prime_table() const { return prime; } std::vector<std::pair<int, int>> prime_power_table(int m) const { assert(m <= n); std::vector<std::pair<int, int>> table(m + 1, {1, 1}); for (int i = 2; i <= m; i++) { int p = sieve[i]; table[i] = {p, p}; if (sieve[i / p] == p) { table[i] = table[i / p]; table[i].second *= p; } } return table; } std::vector<std::pair<int, int>> factorize(int x) { assert(x <= n); std::vector<std::pair<int, int>> res; while (x > 1) { int p = sieve[x]; int exp = 0; if (p < 0) { res.emplace_back(x, 1); break; } while (sieve[x] == p) { x /= p; exp++; } res.emplace_back(p, exp); } return res; } std::vector<int> divisors(int x) { assert(x <= n); std::vector<int> res; res.emplace_back(1); auto pf = factorize(x); for (auto p : pf) { int sz = (int)res.size(); for (int i = 0; i < sz; i++) { int ret = 1; for (int j = 0; j < p.second; j++) { ret *= p.first; res.emplace_back(res[i] * ret); } } } return res; } template <class T> std::vector<T> fast_zeta(const std::vector<T> &f) { std::vector<T> F = f; int sz = f.size(); assert(sz <= n + 1); for (int i = 2; i < sz; i++) { if (sieve[i] != i) continue; for (int j = (sz - 1) / i; j >= 1; j--) { F[j] += F[j * i]; } } return F; } template <class T> std::vector<T> fast_mobius(const std::vector<T> &F) { std::vector<T> f = F; int sz = F.size(); assert(sz <= n + 1); for (int i = 2; i < sz; i++) { if (sieve[i] != i) continue; for (int j = 1; j * i < sz; j++) { f[j] -= f[j * i]; } } return f; } template <class modint> std::vector<modint> pow_table(int k) { std::vector<modint> table(n + 1, 1); table[0] = 0; for (int i = 2; i <= n; i++) { if (sieve[i] == i) { table[i] = modint(i).pow(k); continue; } table[i] = table[sieve[i]] * table[i / sieve[i]]; } return table; } template <class modint> std::vector<modint> inv_table() { return pow_table(modint::mod() - 2); } }; } // namespace ebi #line 2 "modint/modint.hpp" #line 4 "modint/modint.hpp" #include <iostream> #line 2 "modint/base.hpp" #include <concepts> #line 5 "modint/base.hpp" #include <utility> namespace ebi { template <class T> concept Modint = requires(T a, T b) { a + b; a - b; a * b; a / b; a.inv(); a.val(); a.pow(std::declval<long long>()); T::mod(); }; template <Modint mint> std::istream &operator>>(std::istream &os, mint &a) { long long x; os >> x; a = x; return os; } template <Modint mint> std::ostream &operator<<(std::ostream &os, const mint &a) { return os << a.val(); } } // namespace ebi #line 7 "modint/modint.hpp" namespace ebi { template <int m> struct static_modint { private: using modint = static_modint; public: static constexpr int mod() { return m; } static constexpr modint raw(int v) { modint x; x._v = v; return x; } constexpr static_modint() : _v(0) {} constexpr static_modint(long long v) { v %= (long long)umod(); if (v < 0) v += (long long)umod(); _v = (unsigned int)v; } constexpr unsigned int val() const { return _v; } constexpr unsigned int value() const { return val(); } constexpr modint &operator++() { _v++; if (_v == umod()) _v = 0; return *this; } constexpr modint &operator--() { if (_v == 0) _v = umod(); _v--; return *this; } constexpr modint operator++(int) { modint res = *this; ++*this; return res; } constexpr modint operator--(int) { modint res = *this; --*this; return res; } constexpr modint &operator+=(const modint &rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } constexpr modint &operator-=(const modint &rhs) { _v -= rhs._v; if (_v >= umod()) _v += umod(); return *this; } constexpr modint &operator*=(const modint &rhs) { unsigned long long x = _v; x *= rhs._v; _v = (unsigned int)(x % (unsigned long long)umod()); return *this; } constexpr modint &operator/=(const modint &rhs) { return *this = *this * rhs.inv(); } constexpr modint operator+() const { return *this; } constexpr modint operator-() const { return modint() - *this; } constexpr modint pow(long long n) const { assert(0 <= n); modint x = *this, res = 1; while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } constexpr modint inv() const { assert(_v); return pow(umod() - 2); } friend modint operator+(const modint &lhs, const modint &rhs) { return modint(lhs) += rhs; } friend modint operator-(const modint &lhs, const modint &rhs) { return modint(lhs) -= rhs; } friend modint operator*(const modint &lhs, const modint &rhs) { return modint(lhs) *= rhs; } friend modint operator/(const modint &lhs, const modint &rhs) { return modint(lhs) /= rhs; } friend bool operator==(const modint &lhs, const modint &rhs) { return lhs.val() == rhs.val(); } friend bool operator!=(const modint &lhs, const modint &rhs) { return !(lhs == rhs); } private: unsigned int _v = 0; static constexpr unsigned int umod() { return m; } }; using modint998244353 = static_modint<998244353>; using modint1000000007 = static_modint<1000000007>; } // namespace ebi #line 1 "template/template.hpp" #include <bits/stdc++.h> #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--) #define Rep(i, a, n) for (i64 i = (i64)(a); i < (i64)(n); i++) #define RRep(i, a, n) for (i64 i = ((i64)(n)-i64(1)); i >= (i64)(a); i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #line 2 "template/debug_template.hpp" #line 4 "template/debug_template.hpp" namespace ebi { #ifdef LOCAL #define debug(...) \ std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \ debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cerr << " :"; debug_out(t...); } } // namespace ebi #line 2 "template/io.hpp" #line 5 "template/io.hpp" #include <optional> #line 7 "template/io.hpp" namespace ebi { template <typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa) { return os << pa.first << " " << pa.second; } template <typename T1, typename T2> std::istream &operator>>(std::istream &os, std::pair<T1, T2> &pa) { return os >> pa.first >> pa.second; } template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template <typename T> std::istream &operator>>(std::istream &os, std::vector<T> &vec) { for (T &e : vec) std::cin >> e; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const std::optional<T> &opt) { if (opt) { os << opt.value(); } else { os << "invalid value"; } return os; } void fast_io() { std::cout << std::fixed << std::setprecision(15); std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } } // namespace ebi #line 2 "template/utility.hpp" #line 5 "template/utility.hpp" #line 2 "graph/base.hpp" #line 5 "graph/base.hpp" #include <ranges> #line 7 "graph/base.hpp" #line 2 "data_structure/simple_csr.hpp" #line 6 "data_structure/simple_csr.hpp" namespace ebi { template <class E> struct simple_csr { simple_csr() = default; simple_csr(int n, const std::vector<std::pair<int, E>>& elements) : start(n + 1, 0), elist(elements.size()) { for (auto e : elements) { start[e.first + 1]++; } for (auto i : std::views::iota(0, n)) { start[i + 1] += start[i]; } auto counter = start; for (auto [i, e] : elements) { elist[counter[i]++] = e; } } simple_csr(const std::vector<std::vector<E>>& es) : start(es.size() + 1, 0) { int n = es.size(); for (auto i : std::views::iota(0, n)) { start[i + 1] = (int)es[i].size() + start[i]; } elist.resize(start.back()); for (auto i : std::views::iota(0, n)) { std::copy(es[i].begin(), es[i].end(), elist.begin() + start[i]); } } int size() const { return (int)start.size() - 1; } const auto operator[](int i) const { return std::ranges::subrange(elist.begin() + start[i], elist.begin() + start[i + 1]); } auto operator[](int i) { return std::ranges::subrange(elist.begin() + start[i], elist.begin() + start[i + 1]); } const auto operator()(int i, int l, int r) const { return std::ranges::subrange(elist.begin() + start[i] + l, elist.begin() + start[i + 1] + r); } auto operator()(int i, int l, int r) { return std::ranges::subrange(elist.begin() + start[i] + l, elist.begin() + start[i + 1] + r); } private: std::vector<int> start; std::vector<E> elist; }; } // namespace ebi #line 9 "graph/base.hpp" namespace ebi { template <class T> struct Edge { int from, to; T cost; int id; }; template <class E> struct Graph { using cost_type = E; using edge_type = Edge<cost_type>; Graph(int n_) : n(n_) {} Graph() = default; void add_edge(int u, int v, cost_type c) { buff.emplace_back(u, edge_type{u, v, c, m}); edges.emplace_back(edge_type{u, v, c, m++}); } void add_undirected_edge(int u, int v, cost_type c) { buff.emplace_back(u, edge_type{u, v, c, m}); buff.emplace_back(v, edge_type{v, u, c, m}); edges.emplace_back(edge_type{u, v, c, m}); m++; } void read_tree(int offset = 1, bool is_weighted = false) { read_graph(n - 1, offset, false, is_weighted); } void read_parents(int offset = 1) { for (auto i : std::views::iota(1, n)) { int p; std::cin >> p; p -= offset; add_undirected_edge(p, i, 1); } build(); } void read_graph(int e, int offset = 1, bool is_directed = false, bool is_weighted = false) { for (int i = 0; i < e; i++) { int u, v; std::cin >> u >> v; u -= offset; v -= offset; if (is_weighted) { cost_type c; std::cin >> c; if (is_directed) { add_edge(u, v, c); } else { add_undirected_edge(u, v, c); } } else { if (is_directed) { add_edge(u, v, 1); } else { add_undirected_edge(u, v, 1); } } } build(); } void build() { assert(!prepared); csr = simple_csr<edge_type>(n, buff); buff.clear(); prepared = true; } int size() const { return n; } int node_number() const { return n; } int edge_number() const { return m; } edge_type get_edge(int i) const { return edges[i]; } std::vector<edge_type> get_edges() const { return edges; } const auto operator[](int i) const { return csr[i]; } auto operator[](int i) { return csr[i]; } private: int n, m = 0; std::vector<std::pair<int,edge_type>> buff; std::vector<edge_type> edges; simple_csr<edge_type> csr; bool prepared = false; }; } // namespace ebi #line 8 "template/utility.hpp" namespace ebi { template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> T safe_ceil(T a, T b) { if (a % b == 0) return a / b; else if (a >= 0) return (a / b) + 1; else return -((-a) / b); } template <class T> T safe_floor(T a, T b) { if (a % b == 0) return a / b; else if (a >= 0) return a / b; else return -((-a) / b) - 1; } constexpr i64 LNF = std::numeric_limits<i64>::max() / 4; constexpr int INF = std::numeric_limits<int>::max() / 2; const std::vector<int> dy = {1, 0, -1, 0, 1, 1, -1, -1}; const std::vector<int> dx = {0, 1, 0, -1, 1, -1, 1, -1}; } // namespace ebi #line 5 "a.cpp" namespace zoi { // https://zoi-dayo.github.io/atcoder-library/math/factorial.hpp using mint = ebi::modint998244353; const long long B = 1'000'000; constinit std::array<mint, 999> fact1e6 = { 1, 373341033, 45596018, 834980587, 623627864, 428937595, 442819817, 499710224, 833655840, 83857087, 295201906, 788488293, 671639287, 849315549, 597398273, 813259672, 732727656, 244038325, 122642896, 310517972, 160030060, 483239722, 683879839, 712910418, 384710263, 433880730, 844360005, 513089677, 101492974, 959253371, 957629942, 678615452, 34035221, 56734233, 524027922, 31729117, 102311167, 330331487, 8332991, 832392662, 545208507, 594075875, 318497156, 859275605, 300738984, 767818091, 864118508, 878131539, 316588744, 812496962, 213689172, 584871249, 980836133, 54096741, 417876813, 363266670, 335481797, 730839588, 393495668, 435793297, 760025067, 811438469, 720976283, 650770098, 586537547, 117371703, 566486504, 749562308, 708205284, 932912293, 939830261, 983699513, 206579820, 301188781, 593164676, 770845925, 247687458, 41047791, 266419267, 937835947, 506268060, 6177705, 936268003, 166873118, 443834893, 328979964, 470135404, 954410105, 117565665, 832761782, 39806322, 478922755, 394880724, 821825588, 468705875, 512554988, 232240472, 876497899, 356048018, 895187265, 808258749, 575505950, 68190615, 939065335, 552199946, 694814243, 385460530, 529769387, 640377761, 916128300, 440133909, 362216114, 826373774, 502324157, 457648395, 385510728, 904737188, 78988746, 454565719, 623828097, 686156489, 713476044, 63602402, 570334625, 681055904, 222059821, 477211096, 343363294, 833792655, 461853093, 741797144, 74731896, 930484262, 268372735, 941222802, 677432735, 474842829, 700451655, 400176109, 697644778, 390377694, 790010794, 360642718, 505712943, 946647976, 339045014, 715797300, 251680896, 70091750, 40517433, 12629586, 850635539, 110877109, 571935891, 695965747, 634938288, 69072133, 155093216, 749696762, 963086402, 544711799, 724471925, 334646013, 574791029, 722417626, 377929821, 743946412, 988034679, 405207112, 18063742, 104121967, 638607426, 607304611, 751377777, 35834555, 313632531, 18058363, 656121134, 40763559, 562910912, 495867250, 48767038, 210864657, 659137294, 715390025, 865854329, 324322857, 388911184, 286059202, 636456178, 421290700, 832276048, 726437551, 526417714, 252522639, 386147469, 674313019, 274769381, 226519400, 272047186, 117153405, 712896591, 486826649, 119444874, 338909703, 18536028, 41814114, 245606459, 140617938, 250512392, 57084755, 157807456, 261113192, 40258068, 194807105, 325341339, 884328111, 896332013, 880836012, 737358206, 202713771, 785454372, 399586250, 485457499, 640827004, 546969497, 749602473, 159788463, 159111724, 218592929, 675932866, 314795475, 811539323, 246883213, 696818315, 759880589, 4302336, 353070689, 477909706, 559289160, 79781699, 878094972, 840903973, 367416824, 973366814, 848259019, 462421750, 667227759, 897917455, 81800722, 956276337, 942686845, 420541799, 417005912, 272641764, 941778993, 217214373, 192220616, 267901132, 50530621, 652678397, 354880856, 164289049, 781023184, 105376215, 315094878, 607856504, 733905911, 457743498, 992735713, 35212756, 231822660, 276036750, 734558079, 424180850, 433186147, 308380947, 18333316, 12935086, 351491725, 655645460, 535812389, 521902115, 67016984, 48682076, 64748124, 489360447, 361275315, 786336279, 805161272, 468129309, 645091350, 887284732, 913004502, 358814684, 281295633, 328970139, 395955130, 164840186, 820902807, 761699708, 246274415, 592331769, 913846362, 866682684, 600130702, 903837674, 529462989, 90612675, 526540127, 533047427, 110008879, 674279751, 801920753, 645226926, 676886948, 752481486, 474034007, 457790341, 166813684, 287671032, 188118664, 244731384, 404032157, 269766986, 423996017, 182948540, 356801634, 737863144, 652014069, 206068022, 504569410, 919894484, 593398649, 963768176, 882517476, 702523597, 949028249, 128957299, 171997372, 50865043, 20937461, 690959202, 581356488, 369182214, 993580422, 193500140, 540665426, 365786018, 743731625, 144980423, 979536721, 773259009, 617053935, 247670131, 843705280, 30419459, 985463402, 261585206, 237885042, 111276893, 488166208, 137660292, 720784236, 244467770, 26368504, 792857103, 666885724, 670313309, 905683034, 259415897, 512017253, 826265493, 111960112, 633652060, 918048438, 516432938, 386972415, 996212724, 610073831, 444094191, 72480267, 665038087, 11584804, 301029012, 723617861, 113763819, 778259899, 937766095, 535448641, 593907889, 783573565, 673298635, 599533244, 655712590, 173350007, 868198597, 169013813, 585161712, 697502214, 573994984, 285943986, 675831407, 3134056, 965907646, 401920943, 665949756, 236277883, 612745912, 813282113, 892454686, 901222267, 624900982, 927122298, 686321335, 84924870, 927606072, 506664166, 353631992, 165913238, 566073550, 816674343, 864877926, 171259407, 908752311, 874007723, 803597299, 613676466, 880336545, 282280109, 128761001, 58852065, 474075900, 434816091, 364856903, 149123648, 388854780, 314693916, 423183826, 419733481, 888483202, 238933227, 336564048, 757103493, 100189123, 855479832, 51370348, 403061033, 496971759, 831753030, 251718753, 272779384, 683379259, 488844621, 881783783, 659478190, 445719559, 740782647, 546525906, 985524427, 548033568, 333772553, 331916427, 752533273, 730387628, 93829695, 655989476, 930661318, 334885743, 466041862, 428105027, 888238707, 232218076, 769865249, 730641039, 616996159, 231721356, 326973501, 426068899, 722403656, 742756734, 663270261, 364187931, 350431704, 671823672, 633125919, 226166717, 386814657, 237594135, 451479365, 546182474, 119366536, 465211069, 605313606, 728508871, 249619035, 663053607, 900453742, 48293872, 229958401, 62402409, 69570431, 71921532, 960467929, 537087913, 514588945, 513856225, 415497414, 286592050, 645469437, 102052166, 163298189, 873938719, 617583886, 986843080, 962390239, 580971332, 665147020, 88900164, 89866970, 826426395, 616059995, 443012312, 659160562, 229855967, 687413213, 59809521, 398599610, 325666688, 154765991, 159186619, 210830877, 386454418, 84493735, 974220646, 820097297, 2191828, 481459931, 729073424, 551556379, 926316039, 151357011, 808637654, 218058015, 786112034, 850407126, 84202800, 94214098, 30019651, 121701603, 176055335, 865461951, 553631971, 286620803, 984061713, 888573766, 302767023, 977070668, 110954576, 83922475, 51568171, 60949367, 19533020, 510592752, 615419476, 341370469, 912573425, 286207526, 206707897, 384156962, 414163604, 193301813, 749570167, 366933789, 11470970, 600191572, 391667731, 328736286, 30645366, 215162519, 604947226, 236199953, 718439098, 411423177, 803407599, 632441623, 766760224, 263006576, 757681534, 61082578, 681666415, 947466395, 12206799, 659767098, 933746852, 978860867, 59215985, 161179205, 439197472, 259779111, 511621808, 145770512, 882749888, 943124465, 872053396, 631078482, 166861622, 743415395, 772287179, 602427948, 924112080, 385643091, 794973480, 883782693, 869723371, 805963889, 313106351, 262132854, 400034567, 488248149, 265769800, 791715397, 408753255, 468381897, 415812467, 172922144, 64404368, 281500398, 512318142, 288791777, 955559118, 242484726, 536413695, 205340854, 707803527, 576699812, 218525078, 875554190, 46283078, 833841915, 763148293, 807722138, 788080170, 556901372, 150896699, 253151120, 97856807, 918256774, 771557187, 582547026, 472709375, 911615063, 743371401, 641382840, 446540967, 184639537, 157247760, 775930891, 939702814, 499082462, 19536133, 548753627, 593243221, 563850263, 185475971, 687419227, 396799323, 657976136, 864535682, 433009242, 860830935, 33107339, 517661450, 467651311, 812398757, 202133852, 431839017, 709549400, 99643620, 773282878, 290471030, 61134552, 129206504, 929147251, 837008968, 422332597, 353775281, 469563025, 62265336, 835064501, 851685235, 21197005, 264793769, 326416680, 118842991, 84257200, 763248924, 687559609, 150907932, 401832452, 242726978, 766752066, 959173604, 390269102, 992293822, 744816299, 476631694, 177284763, 702429415, 374065901, 169855231, 629007616, 719169602, 564737074, 475119050, 714502830, 40993711, 820235888, 749063595, 239329111, 612759169, 18591377, 419142436, 442202439, 941600951, 158013406, 637073231, 471564060, 447222237, 701248503, 599797734, 577221870, 69656699, 51052704, 6544303, 10958310, 554955500, 943192237, 192526269, 897983911, 961628039, 240232720, 627280533, 710239542, 70255649, 261743865, 228474833, 776408079, 304180483, 63607040, 953297493, 758058902, 395529997, 156010331, 825833840, 539880795, 234683685, 52626619, 751843490, 116909119, 62806842, 574857555, 353417551, 40061330, 822203768, 681051568, 490913702, 9322961, 766631257, 124794668, 37844313, 163524507, 729108319, 490867505, 47035168, 682765157, 53842115, 817965276, 757179922, 339238384, 909741023, 150530547, 158444563, 140949492, 993302799, 551621442, 137578883, 475122706, 443869843, 605400098, 689361523, 769596520, 801661499, 474900284, 586624857, 349960501, 134084537, 650564083, 877097974, 379857427, 887890124, 159436401, 133274277, 986182139, 729720334, 568925901, 459461496, 499309445, 493171177, 460958750, 380694152, 168836226, 840160881, 141116880, 225064950, 109618190, 842341383, 85305729, 759273275, 97369807, 669317759, 766247510, 829017039, 550323884, 261274540, 918239352, 29606025, 870793828, 293683814, 378510746, 367270918, 481292028, 813097823, 798448487, 230791733, 899305835, 504040630, 162510533, 479367951, 275282274, 806951470, 462774647, 56473153, 184659008, 905122161, 664034750, 109726629, 59372704, 325795100, 486860143, 843736533, 924723613, 880348000, 801252478, 616515290, 776142608, 284803450, 583439582, 274826676, 6018349, 377403437, 244041569, 527081707, 544763288, 708818585, 354033051, 904309832, 589922898, 673933870, 682858433, 945260111, 899893421, 515264973, 911685911, 9527148, 239480646, 524126897, 48259065, 578214879, 118677219, 786127243, 869205770, 923276513, 937928886, 802186160, 12198440, 638784295, 34200904, 758925811, 185027790, 80918046, 120604699, 610456697, 573601211, 208296321, 49743354, 653691911, 490750754, 674335312, 887877110, 875880304, 308360096, 414636410, 886100267, 8525751, 636257427, 558338775, 500159951, 696213291, 97268896, 364983542, 937928436, 641582714, 586211304, 345265657, 994704486, 443549763, 207259440, 302122082, 166055224, 623250998, 239642551, 476337075, 283167364, 211328914, 68064804, 950202136, 187552679, 18938709, 646784245, 598764068, 538505481, 610424991, 864445053, 390248689, 278395191, 686098470, 935957187, 868529577, 329970687, 804930040, 84992079, 474569269, 810762228, 573258936, 756464212, 155080225, 286966169, 283614605, 19283401, 24257676, 871831819, 612689791, 846988741, 617120754, 971716517, 979541482, 297910784, 991087897, 783825907, 214821357, 689498189, 405026419, 946731704, 609346370, 707669156, 457703127, 957341187, 980735523, 649367684, 791011898, 82098966, 234729712, 105002711, 130614285, 291032164, 193188049, 363211260, 58108651, 100756444, 954947696, 346032213, 863300806, 36876722, 622610957, 289232396, 667938985, 734886266, 395881057, 417188702, 183092975, 887586469, 83334648, 797819763, 100176902, 781587414, 841864935, 371674670, 18247584}; mint fact(long long n) { if (n >= mint::mod()) return 0; mint ans = fact1e6[n / B]; for (int i = n / B + 1; i <= n; ++i) { ans *= i; } return ans; } } namespace ebi { using mint = modint998244353; void main_() { int n, k; std::cin >> n >> k; linear_sieve sieve(k + 10); mint ans = 0; { auto pow_table = sieve.pow_table<mint>(k); std::vector<mint> f(k + 2); rep(i, 1, k + 2) { f[i] = f[i - 1] + pow_table[i]; } ans += n * lagrange_interpolation(f, n - 1); } { auto pow_table = sieve.pow_table<mint>(k + 1); std::vector<mint> f(k + 3); rep(i, 1, k + 3) { f[i] = f[i - 1] + pow_table[i]; } ans -= lagrange_interpolation(f, n - 1); } ans *= 2; ans *= zoi::fact(n-1); std::cout << ans << '\n'; } } // namespace ebi int main() { ebi::fast_io(); int t = 1; // std::cin >> t; while (t--) { ebi::main_(); } return 0; }