結果
| 問題 | No.194 フィボナッチ数列の理解(1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-05 02:49:19 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 773 ms / 5,000 ms |
| コード長 | 39,538 bytes |
| 記録 | |
| コンパイル時間 | 8,645 ms |
| コンパイル使用メモリ | 335,708 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2026-03-05 02:49:54 |
| 合計ジャッジ時間 | 13,310 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
コンパイルメッセージ
YRS/po/coef_of_rational_fps.hpp: In instantiation of 'T coef_of_rational_fps_ntt(vc<T>, vc<T>, ll) [with T = mint_t<1000000007>; vc<T> = std::vector<mint_t<1000000007>, std::allocator<mint_t<1000000007> > >; ll = long long int]': YRS/po/coef_of_rational_fps.hpp:79:57: required from 'T coef_of_rational_fps(vc<T>, vc<T>, ll) [with T = mint_t<1000000007>; vc<T> = std::vector<mint_t<1000000007>, std::allocator<mint_t<1000000007> > >; ll = long long int]' YRS/po/line_inte.hpp:14:30: required from 'T line_inte(vc<T>, ll, int) [with T = mint_t<1000000007>; vc<T> = std::vector<mint_t<1000000007>, std::allocator<mint_t<1000000007> > >; ll = long long int]' No_194_フィボナッチ数列の理解_1.cpp:23:18: required from here YRS/po/coef_of_rational_fps.hpp:18:24: warning: left shift count is negative [-Wshift-count-negative]
ソースコード
#line 1 "No_194_\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u5217\u306e\u7406\u89e3_1.cpp"
#define YRSD
// #include "YRS/aa/fast.hpp"
#line 2 "YRS/all.hpp"
#line 2 "YRS/aa/head.hpp"
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <bit>
#include <chrono>
#include <functional>
#include <iomanip>
#include <utility>
#include <type_traits>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <limits>
#include <ranges>
#include <concepts>
#define TE template <typename T>
#define TES template <typename T, typename ...S>
#define Z auto
#define ep emplace_back
#define eb emplace
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define ov(a, b, c, d, e, ...) e
#define FO1(a) for (int _ = 0; _ < (a); ++_)
#define FO2(i, a) for (int i = 0; i < (a); ++i)
#define FO3(i, a, b) for (int i = (a); i < (b); ++i)
#define FO4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define FOR(...) ov(__VA_ARGS__, FO4, FO3, FO2, FO1)(__VA_ARGS__)
#define FF1(a) for (int _ = (a) - 1; _ >= 0; --_)
#define FF2(i, a) for (int i = (a) - 1; i >= 0; --i)
#define FF3(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define FF4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define FOR_R(...) ov(__VA_ARGS__, FF4, FF3, FF2, FF1)(__VA_ARGS__)
#define FOR_subset(t, s) for (int t = (s); t > -1; t = (t == 0 ? -1 : (t - 1) & s))
#define sort ranges::sort
using namespace std;
TE using vc = vector<T>;
TE using vvc = vc<vc<T>>;
TE using T1 = tuple<T>;
TE using T2 = tuple<T, T>;
TE using T3 = tuple<T, T, T>;
TE using T4 = tuple<T, T, T, T>;
TE using max_heap = priority_queue<T>;
TE using min_heap = priority_queue<T, vc<T>, greater<T>>;
using u8 = unsigned char; using uint = unsigned int; using ll = long long; using ull = unsigned long long;
using ld = long double; using i128 = __int128; using u128 = __uint128_t; using f128 = __float128;
using u16 = uint16_t;
using PII = pair<int, int>; using PLL = pair<ll, ll>;
#ifdef YRSD
constexpr bool dbg = 1;
#else
constexpr bool dbg = 0;
#endif
#line 2 "YRS/IO/IO.hpp"
istream &operator>>(istream &I, i128 &x) {
static string s;
I >> s;
int f = s[0] == '-';
x = 0;
const int N = (int)s.size();
FOR(i, f, N) x = x * 10 + s[i] - '0';
if (f) x = -x;
return I;
}
ostream &operator<<(ostream &O, i128 x) {
static string s;
s.clear();
bool f = x < 0;
if (f) x = -x;
while (x) s += '0' + x % 10, x /= 10;
if (s.empty()) s += '0';
if (f) s += '-';
reverse(all(s));
return O << s;
}
istream &operator>>(istream &I, f128 &x) {
static string s;
I >> s, x = stold(s);
return I;
}
ostream &operator<<(ostream &O, const f128 x) { return O << ld(x); }
template <typename... S>
istream &operator>>(istream &I, tuple<S...> &t) {
return apply([&I](Z &...s) { ((I >> s), ...); }, t), I;
}
template <typename T, typename U>
istream &operator>>(istream &I, pair<T, U> &x) {
return I >> x.fi >> x.se;
}
template <typename T, typename U>
ostream &operator<<(ostream &O, const pair<T, U> &x) {
return O << x.fi << ' ' << x.se;
}
TE requires requires(T &c) { begin(c); end(c); } and
(not is_same_v<decay_t<T>, string>)
istream &operator>>(istream &I, T &c) {
for (Z &e : c) I >> e;
return I;
}
TE requires requires(const T &c) { begin(c); end(c); } and
(not is_same_v<decay_t<T>, const char*>) and
(not is_same_v<decay_t<T>, string>) and
(not is_array_v<remove_reference_t<T>> or
not is_same_v<remove_extent_t<remove_reference_t<T>>, char>)
ostream &operator<<(ostream &O, const T &a) {
if (a.empty()) return O;
Z i = a.begin();
O << *i++;
for (; i != a.end(); ++i) O << ' ' << *i;
return O;
}
void IN() {}
TE void IN(T &x, Z &...s) { cin >> x, IN(s...); }
void print() { cout << '\n'; }
TES void print(T &&x, S &&...y) {
cout << x;
if constexpr (sizeof...(S)) cout << ' ';
print(forward<S>(y)...);
}
void put() {}
TES void put(T &&x, S &&...y) {
cout << x;
put(forward<S>(y)...);
}
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define UINT(...) uint __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; IN(__VA_ARGS__)
#define I128(...) i128 __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CH(...) char __VA_ARGS__; IN(__VA_ARGS__)
#define REAL(...) re __VA_ARGS__; IN(__VA_ARGS__)
#define VEC(T, a, n) vc<T> a(n); IN(a)
void YES(bool o = 1) { print(o ? "YES" : "NO"); }
void Yes(bool o = 1) { print(o ? "Yes" : "No"); }
void yes(bool o = 1) { print(o ? "yes" : "no"); }
void NO(bool o = 1) { YES(not o); }
void No(bool o = 1) { Yes(not o); }
void no(bool o = 1) { yes(not o); }
void ALICE(bool o = 1) { print(o ? "ALICE" : "BOB"); }
void Alice(bool o = 1) { print(o ? "Alice" : "Bob"); }
void alice(bool o = 1) { print(o ? "alice" : "bob"); }
void BOB(bool o = 1) { ALICE(not o); }
void Bob(bool o = 1) { Alice(not o); }
void bob(bool o = 1) { alice(not o); }
void POSSIBLE(bool o = 1) { print(o ? "POSSIBLE" : "IMPOSSIBLE"); }
void Possible(bool o = 1) { print(o ? "Possible" : "Impossible"); }
void possible(bool o = 1) { print(o ? "possible" : "impossible"); }
void IMPOSSIBLE(bool o = 1) { POSSIBLE(not o); }
void Impossible(bool o = 1) { Possible(not o); }
void impossible(bool o = 1) { possible(not o); }
void TAK(bool o = 1) { print(o ? "TAK" : "NIE"); }
void NIE(bool o = 1) { TAK(not o); }
#line 5 "YRS/all.hpp"
#if (__cplusplus >= 202002L)
#include <numbers>
constexpr ld pi = numbers::pi_v<ld>;
#endif
TE constexpr T inf = numeric_limits<T>::max();
template <> constexpr i128 inf<i128> = i128(inf<ll>) * 2'000'000'000'000'000'000;
template <typename T, typename U>
constexpr pair<T, U> inf<pair<T, U>> = {inf<T>, inf<U>};
TE constexpr static inline int pc(T x) { return popcount(make_unsigned_t<T>(x)); }
constexpr static inline ll len(const Z &a) { return a.size(); }
void reverse(Z &a) { reverse(all(a)); }
void unique(Z &a) {
sort(a);
a.erase(unique(all(a)), a.end());
}
TE vc<int> inverse(const vc<T> &a) {
int N = len(a);
vc<int> b(N, -1);
FOR(i, N) if (a[i] != -1) b[a[i]] = i;
return b;
}
Z QMAX(const Z &a) { return *max_element(all(a)); }
Z QMIN(const Z &a) { return *min_element(all(a)); }
TE Z QMAX(T l, T r) { return *max_element(l, r); }
TE Z QMIN(T l, T r) { return *min_element(l, r); }
constexpr bool chmax(Z &a, const Z &b) { return (a < b ? a = b, 1 : 0); }
constexpr bool chmin(Z &a, const Z &b) { return (a > b ? a = b, 1 : 0); }
vc<int> argsort(const Z &a) {
vc<int> I(len(a));
iota(all(I), 0);
sort(I, [&](int i, int k) { return a[i] < a[k] or (a[i] == a[k] and i < k); });
return I;
}
TE vc<T> rearrange(const vc<T> &a, const vc<int> &I) {
int N = len(I);
vc<T> b(N);
FOR(i, N) b[i] = a[I[i]];
return b;
}
template <int of = 1, typename T>
vc<T> pre_sum(const vc<T> &a) {
int N = len(a);
vc<T> c(N + 1);
FOR(i, N) c[i + 1] = c[i] + a[i];
if (of == 0) c.erase(c.begin());
return c;
}
TE constexpr static int topbit(T x) {
if (x == 0) return - 1;
if constexpr (sizeof(T) <= 4) return 31 - __builtin_clz(x);
else return 63 - __builtin_clzll(x);
}
TE constexpr static int lowbit(T x) {
if (x == 0) return -1;
if constexpr (sizeof(T) <= 4) return __builtin_ctz(x);
else return __builtin_ctzll(x);
}
TE constexpr T floor(T x, T y) { return x / y - (x % y and (x ^ y) < 0); }
TE constexpr T ceil(T x, T y) { return floor(x + y - 1, y); }
TE constexpr T bmod(T x, T y) { return x - floor(x, y) * y; }
TE constexpr pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return pair{q, x - q * y};
}
template <typename T = ll>
T SUM(const Z &v) {
return accumulate(all(v), T(0));
}
int lb(const Z &a, Z x) { return lower_bound(all(a), x) - a.begin(); }
TE int lb(T l, T r, Z x) { return lower_bound(l, r, x) - l; }
int ub(const Z &a, Z x) { return upper_bound(all(a), x) - a.begin(); }
TE int ub(T l, T r, Z x) { return upper_bound(l, r, x) - l; }
template <bool ck = 1>
ll bina(Z f, ll l, ll r) {
if constexpr (ck) assert(f(l));
while (abs(l - r) > 1) {
ll x = (r + l) >> 1;
(f(x) ? l : r) = x;
}
return l;
}
TE T bina_real(Z f, T l, T r, int c = 100) {
while (c--) {
T x = (l + r) / 2;
(f(x) ? l : r) = x;
}
return (l + r) / 2;
}
Z pop(Z &s) {
if constexpr (requires { s.pop_back(); }) {
Z x = s.back();
return s.pop_back(), x;
} else if constexpr (requires { s.top(); }) {
Z x = s.top();
return s.pop(), x;
} else {
Z x = s.front();
return s.pop(), x;
}
}
void setp(int x) { cout << fixed << setprecision(x); }
TE inline void sh(vc<T> &a, int N, T b = {}) {
a.resize(N, b);
}
#line 1 "YRS/debug.hpp"
#ifdef YRSD
void DBG() { cerr << "]" << endl; }
TES void DBG(T &&x, S &&...y) {
cerr << x;
if constexpr (sizeof...(S)) cerr << ", ";
DBG(forward<S>(y)...);
}
#define debug(...) cerr << "[" << __LINE__ << "]: [" #__VA_ARGS__ "] = [", DBG(__VA_ARGS__)
void ERR() { cerr << endl; }
TES void ERR(T &&x, S &&...y) {
cerr << x;
if constexpr (sizeof...(S)) cerr << ", ";
ERR(forward<S>(y)...);
}
#define err(...) cerr << "[" << __LINE__ << "]: ", ERR(__VA_ARGS__)
#define asser assert
#else
#define debug(...) void(0721)
#define err(...) void(0721)
#endif
#line 5 "No_194_\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u5217\u306e\u7406\u89e3_1.cpp"
// #include "YRS/IO/fast_io.hpp"
// #include "YRS/random/rng.hpp"
// #include "YRS/ds/basic/retsu.hpp"
// #include "YRS/mod/binom.hpp"
#line 2 "YRS/al/m/add.hpp"
template <typename T>
struct monoid_add {
using X = T;
static constexpr inline X op(const X &x, const X &y) { return x + y; }
static constexpr inline X inv(const X &x) { return -x; }
static constexpr inline X pow(const X &x, ll n) { return X(n) * x; }
static constexpr inline X unit() { return X(0); }
static constexpr bool commute = 1;
};
#line 2 "YRS/ds/seg/range_sum_point_add.hpp"
template <typename T, uint B = 1 << 5>
struct range_sum_point_add : T {
using X = T::X;
using T::op, T::unit;
int N;
vc<X> a;
range_sum_point_add(int N) { build(N); }
range_sum_point_add(int N, Z f) { build(N, f); }
range_sum_point_add(const vc<X> &a) { build(a); }
void build(int m) {
N = m;
a.assign(N << 1, unit());
}
void build(int m, Z f) {
N = m;
a.assign(N << 1, unit());
FOR(i, N) a[i + N] = f(i);
FOR_R(i, 1, N << 1) a[i / B] = op(a[i / B], a[i]);
}
void build(const vc<X> &c) {
N = len(c);
a.assign(N << 1, unit());
FOR(i, N) a[i + N] = c[i];
FOR_R(i, 1, N << 1) a[i / B] = op(a[i / B], a[i]);
}
void multiply(uint i, X x) {
a[i += N] += x;
while (i /= B) a[i] += x;
}
X prod(uint l, uint r) {
l += N, r += N;
X ls = unit(), rs = ls;
while (l / B != r / B) {
while (l & (B - 1)) ls = op(ls, a[l++]);
while (r & (B - 1)) rs = op(rs, a[--r]);
l /= B, r /= B;
}
for (uint i = l; i < r; ++i) ls = op(ls, a[i]);
return op(ls, rs);
}
vc<X> get_all() { return vc<X>(begin(a) + N, begin(a) + N + N); }
};
#line 2 "YRS/po/line_inte.hpp"
#line 2 "YRS/po/coef_of_rational_fps.hpp"
#line 2 "YRS/po/fps_div.hpp"
#line 2 "YRS/po/c/count_terms.hpp"
// 非 0 数量
template<typename mint>
int count_terms(const vc<mint> &f){
int s = 0, N = len(f);
FOR(i, N) if(f[i] != mint(0)) ++s;
return s;
}
#line 2 "YRS/po/fps_inv.hpp"
#line 2 "YRS/po/convolution.hpp"
#line 2 "YRS/po/c/ntt.hpp"
#line 2 "YRS/mod/mint.hpp"
#line 2 "YRS/mod/modint_common.hpp"
TE static vc<T> &invs() {
static vc<T> a{0, 1};
return a;
}
TE static vc<T> &fac() {
static vc<T> a{1, 1};
return a;
}
TE static vc<T> &ifac() {
static vc<T> a{1, 1};
return a;
}
TE static int Set_inv(int N) {
static vc<T> &inv = invs<T>();
if (len(inv) >= N) return N;
inv.resize(N + 1);
inv[0] = 1, inv[1] = 1;
FOR(i, 1, N) inv[i + 1] = inv[i] * i;
T t = pop(inv).inv();
FOR_R(i, N) inv[i] *= t, t *= i;
return N;
}
TE static int Set_comb(int N) {
static vc<T> &fa = fac<T>(), &ifa = ifac<T>();
if (len(fa) >= N) return N;
fa.resize(N);
ifa.resize(N);
FOR(i, 1, N) fa[i] = fa[i - 1] * i;
ifa[N - 1] = fa[N - 1].inv();
FOR_R(i, N - 1) ifa[i] = ifa[i + 1] * (i + 1);
return N;
}
template <typename mint>
mint inv(int n) {
static const int mod = mint::get_mod();
static vc<mint> &a = invs<mint>();
assert(0 <= n);
while (len(a) <= n) {
int k = len(a);
int q = (mod + k - 1) / k;
int r = k * q - mod;
a.ep(a[r] * mint(q));
}
return a[n];
}
template <typename mint>
mint fact(int n) {
static const int mod = mint::get_mod();
static vc<mint> &a = fac<mint>();
assert(0 <= n);
if (n >= mod) return 0;
while (len(a) <= n) {
int k = len(a);
a.ep(a[k - 1] * mint(k));
}
return a[n];
}
template <typename mint>
mint fact_inv(int n) {
static vc<mint> &a = ifac<mint>();
if (n < 0) return mint(0);
while (len(a) <= n)
a.ep(a[len(a) - 1] * inv<mint>(len(a)));
return a[n];
}
template <typename mint, typename... Ts>
mint fact_invs(Ts... xs) {
return (mint(1) * ... * fact_inv<mint>(xs));
}
template <typename mint, typename X, typename... S>
mint multinomial(X&& a, S&&... b) {
return fact<mint>(a) * fact_invs<mint>(forward<S>(b)...);
}
template <typename mint>
mint C_dense(int n, int k) {
assert(n >= 0);
if (k < 0 or n < k) return 0;
static vc<vc<mint>> C;
static int H = 0, W = 0;
Z calc = [&](int i, int j) -> mint {
if (i == 0) return(j == 0 ? mint(1) : mint(0));
return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
};
if (W <= k) {
for (int i = 0; i < H; ++i) {
C[i].resize(k + 1);
for (int j = W; j < k + 1; ++j) {
C[i][j] = calc(i, j);
}
}
W = k + 1;
}
if (H <= n) {
C.resize(n + 1);
for (int i = H; i < n + 1; ++i) {
C[i].resize(W);
for (int j = 0; j < W; ++j) {
C[i][j] = calc(i, j);
}
}
H = n + 1;
}
return C[n][k];
}
template <typename mint>
mint C(int N, int K) {
assert(N >= 0);
if (K < 0 or N < K) return 0;
return fact<mint>(N) * fact_inv<mint>(K) * fact_inv<mint>(N - K);
}
template <typename mint>
mint lucas(ll N, ll K) {
static constexpr int P = mint::get_mod();
if (K > N) return 0;
if (K == 0) return 1;
return C<mint>(N % P, K % P) * lucas<mint>(N / P, K / P);
}
template <typename mint, bool large = false, bool dense = false>
mint binom(ll n, ll k) {
assert(n >= 0);
if (k < 0 or n < k) return 0;
if constexpr (dense) return C_dense<mint>(n, k);
if constexpr (not large) return multinomial<mint>(n, k, n - k);
k = min(k, n - k);
mint x(1);
FOR(i, k) x *= mint(n - i);
return x * fact_inv<mint>(k);
}
template <typename mint, bool large = false>
mint C_inv(ll n, ll k) {
assert(n >= 0);
assert(0 <= k and k <= n);
if (not large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k);
return mint(1) / binom<mint, 1>(n, k);
}
// [x^d](1-x)^{-n}
template <typename mint, bool large = false, bool dense = false>
mint C_negative(ll n, ll d) {
assert(n >= 0);
if (d < 0) return mint(0);
if (n == 0) return (d == 0 ? mint(1) : mint(0));
return binom<mint, large, dense>(n + d - 1, d);
}
#define fac fact<T>
#define ifac fact_inv<T>
#define CC C<mint>
#define set_comb Set_comb<mint>
#define set_inv Set_inv<mint>
#line 2 "YRS/mod/mint_t.hpp"
#define c constexpr
template <int mod>
struct mint_t {
using T = mint_t;
static c uint m = mod;
uint x;
c inline uint val() const { return x; }
c mint_t() : x(0) {}
c mint_t(uint x) : x(x % m) {}
c mint_t(ull x) : x(x % m) {}
c mint_t(u128 x) : x(x % m) {}
c mint_t(int x) : x((x %= mod) < 0 ? x + mod : x) {}
c mint_t(ll x) : x((x %= mod) < 0 ? x + mod : x) {}
c mint_t(i128 x) : x((x %= mod) < 0 ? x + mod : x) {}
c T &operator+=(T p) {
if ((x += p.x) >= m) x -= m;
return *this;
}
c T &operator-=(T p) {
if ((x += m - p.x) >= m) x -= m;
return *this;
}
c T operator+(T p) const { return T(*this) += p; }
c T operator-(T p) const { return T(*this) -= p; }
c T &operator*=(T p) {
x = ull(x) * p.x % m;
return *this;
}
c T operator*(T p) const { return T(*this) *= p; }
c T &operator/=(T p) { return *this *= p.inv(); }
c T operator/(T p) const { return T(*this) /= p; }
c T operator-() const { return T::gen(x ? mod - x : 0); }
c T inv() const {
int a = x, b = mod, x = 1, y = 0;
while (b > 0) {
int t = a / b;
swap(a -= t * b, b);
swap(x -= t * y, y);
}
return T(x);
}
c T pow(ll k) const {
if (k < 0) return inv().pow(-k);
T s(1), a(x);
for (; k; k >>= 1, a *= a)
if (k & 1) s *= a;
return s;
}
c bool operator<(T p) const { return x < p.x; }
c bool operator==(T p) const { return x == p.x; }
c bool operator!=(T p) const { return x != p.x; }
static c T gen(uint x) {
T s;
s.x = x;
return s;
}
friend istream &operator>>(istream &cin, T &p) {
ll t;
cin >> t;
p = t;
return cin;
}
friend ostream &operator<<(ostream &cout, T p) { return cout << p.x; }
static c int get_mod() { return mod; }
static c PII ntt_info() {
if (mod == 167772161) return {25, 17};
if (mod == 469762049) return {26, 30};
if (mod == 754974721) return {24, 362};
if (mod == 998244353) return {23, 31};
if (mod == 120586241) return {20, 74066978};
if (mod == 880803841) return {23, 211};
if (mod == 943718401) return {22, 663003469};
if (mod == 1004535809) return {21, 582313106};
if (mod == 1012924417) return {21, 368093570};
return {-1, -1};
}
static c bool can_ntt() { return ntt_info().fi != -1; }
};
#undef c
using M99 = mint_t<998244353>;
using M17 = mint_t<1000000007>;
#ifdef FIO
template <int mod>
void rd(mint_t<mod> &x) {
LL(y);
x = y;
}
template <int mod>
void wt(mint_t<mod> x) {
wt(x.x);
}
#endif
#line 4 "YRS/po/c/ntt.hpp"
TE void ntt(vc<T> &a, bool in) {
assert(T::can_ntt());
const int p = T::ntt_info().fi;
const uint m = T::get_mod();
static array<T, 30> r, ir, ra, ira, rat, irat;
assert(p != -1 and len(a) <= (1 << max(0, p)));
static bool ok = 0;
if (not ok) {
ok = 1;
r[p] = T::ntt_info().se;
ir[p] = T(1) / r[p];
FOR_R(i, p) {
r[i] = r[i + 1] * r[i + 1];
ir[i] = ir[i + 1] * ir[i + 1];
}
T s = 1, in = 1;
FOR(i, p - 1) {
ra[i] = r[i + 2] * s;
ira[i] = ir[i + 2] * in;
s *= ir[i + 2];
in *= r[i + 2];
}
s = 1, in = 1;
FOR(i, p - 2) {
rat[i] = r[i + 3] * s;
irat[i] = ir[i + 3] * in;
s *= ir[i + 3];
in *= r[i + 3];
}
}
int N = len(a), n = topbit(N);
if (not in) {
int sz = 0;
while (sz < n) {
if (n - sz == 1) {
int p = 1 << (n - sz - 1);
T c = 1;
FOR(s, 1 << sz) {
int of = s << (n - sz);
FOR(i, p) {
T l = a[i + of], r = a[i + of + p] * c;
a[i + of] = l + r, a[i + of + p] = l - r;
}
c *= ra[topbit(~s & -~s)];
}
++sz;
} else {
int p = 1 << (n - sz - 2);
T c = 1, in = r[2];
FOR(s, 1 << sz) {
T r2 = c * c, r3 = r2 * c;
int of = s << (n - sz);
FOR(i, p) {
const ull mm = ull(m) * m;
ull a0 = a[i + of].val(), a1 = ull(a[i + of + p].val()) * c.val();
ull aa = ull(a[i + of + 2 * p].val()) * r2.val();
ull bb = ull(a[i + of + 3 * p].val()) * r3.val();
ull t = (a1 + mm - bb) % m * in.val();
ull na = mm - aa;
a[i + of] = a0 + a1 + aa + bb;
a[i + of + p] = a0 + aa + mm * 2 - a1 - bb;
a[i + of + 2 * p] = a0 + na + t;
a[i + of + 3 * p] = a0 + na + mm - t;
}
c *= rat[topbit(~s & -~s)];
}
sz += 2;
}
}
} else {
T c = T(1) / T(N);
FOR(i, N) a[i] *= c;
int sz = n;
while (sz) {
if (sz == 1) {
int p = 1 << (n - sz);
T c = 1;
FOR(s, 1 << (sz - 1)) {
int of = s << (n - sz + 1);
FOR(i, p) {
ull l = a[i + of].val(), r = a[i + of + p].val();
a[i + of] = l + r;
a[i + of + p] = (m + l - r) * c.val();
}
c *= ira[topbit(~s & -~s)];
}
--sz;
} else {
int p = 1 << (n - sz);
T c = 1, in = ir[2];
FOR(s, 1 << (sz - 2)) {
T r2 = c * c, r3 = r2 * c;
int of = s << (n - sz + 2);
FOR(i, p) {
ull a0 = a[i + of].val(), a1 = a[i + of + p].val();
ull aa = a[i + of + 2 * p].val();
ull bb = a[i + of + 3 * p].val();
ull x = (m + aa - bb) * in.val() % m;
a[i + of] = a0 + a1 + aa + bb;
a[i + of + p] = (a0 + m - a1 + x) * c.val();
a[i + of + 2 * p] = (a0 + a1 + 2 * m - aa - bb) * r2.val();
a[i + of + 3 * p] = (a0 + 2 * m - a1 - x) * r3.val();
}
c *= irat[topbit(~s & -~s)];
}
sz -= 2;
}
}
}
}
#line 2 "YRS/mod/crt3.hpp"
constexpr uint pw_c(ull a, ull b, uint mod) {
a %= mod;
ull res = 1;
FOR(32) {
if (b & 1) res = res * a % mod;
a = a * a % mod, b >>= 1;
}
return res;
}
template <typename T, uint p0, uint p1>
T crt(ull a0, ull a1) {
static_assert(p0 < p1);
static constexpr ull x0_1 = pw_c(p0, p1 - 2, p1);
ull c = (a1 - a0 + p1) * x0_1 % p1;
return a0 + c * p0;
}
template <typename T, uint p0, uint p1, uint p2>
T crt(ull a0, ull a1, ull a2) {
static_assert(p0 < p1 and p1 < p2);
static constexpr ull x1 = pw_c(p0, p1 - 2, p1);
static constexpr ull x2 = pw_c(ull(p0) * p1 % p2, p2 - 2, p2);
static constexpr ull p01 = ull(p0) * p1;
ull c = (a1 - a0 + p1) * x1 % p1;
ull ans_1 = a0 + c * p0;
c = (a2 - ans_1 % p2 + p2) * x2 % p2;
return T(ans_1) + T(c) * T(p01);
}
template <typename T, uint p0, uint p1, uint p2, uint p3>
T crt(ull a0, ull a1, ull a2, ull a3) {
static_assert(p0 < p1 and p1 < p2 and p2 < p3);
static constexpr ull x1 = pw_c(p0, p1 - 2, p1);
static constexpr ull x2 = pw_c(ull(p0) * p1 % p2, p2 - 2, p2);
static constexpr ull x3 = pw_c(ull(p0) * p1 % p3 * p2 % p3, p3 - 2, p3);
static constexpr ull p01 = ull(p0) * p1;
ull c = (a1 - a0 + p1) * x1 % p1;
ull ans_1 = a0 + c * p0;
c = (a2 - ans_1 % p2 + p2) * x2 % p2;
u128 ans_2 = ans_1 + c * u128(p01);
c = (a3 - ans_2 % p3 + p3) * x3 % p3;
return T(ans_2) + T(c) * T(p01) * T(p2);
}
template <typename T, uint p0, uint p1, uint p2, uint p3, uint p4>
T crt(ull a0, ull a1, ull a2, ull a3, ull a4) {
static_assert(p0 < p1 and p1 < p2 and p2 < p3 and p3 < p4);
static constexpr ull x1 = pw_c(p0, p1 - 2, p1);
static constexpr ull x2 = pw_c(ull(p0) * p1 % p2, p2 - 2, p2);
static constexpr ull x3 = pw_c(ull(p0) * p1 % p3 * p2 % p3, p3 - 2, p3);
static constexpr ull x4 = pw_c(ull(p0) * p1 % p4 * p2 % p4 * p3 % p4, p4 - 2, p4);
static constexpr ull p01 = ull(p0) * p1;
static constexpr ull p23 = ull(p2) * p3;
ull c = (a1 - a0 + p1) * x1 % p1;
ull ans_1 = a0 + c * p0;
c = (a2 - ans_1 % p2 + p2) * x2 % p2;
u128 ans_2 = ans_1 + c * u128(p01);
c = ull(a3 - ans_2 % p3 + p3) * x3 % p3;
u128 ans_3 = ans_2 + u128(c * p2) * p01;
c = ull(a4 - ans_3 % p4 + p4) * x4 % p4;
return T(ans_3) + T(c) * T(p01) * T(p23);
}
#line 5 "YRS/po/convolution.hpp"
TE vc<T> conv_naive(const vc<T> &a, const vc<T> &b) {
int N = len(a), M = len(b), sz = N + M - 1;
if (not N or not M) return {};
if (N > M) return conv_naive(b, a);
vc<T> c(sz);
FOR(i, N) FOR(k, M) c[i + k] += a[i] * b[k];
return c;
}
TE vc<T> conv_kara(const vc<T> &f, const vc<T> &g) {
constexpr int lm = 30;
if (min(len(f), len(g)) <= lm) return conv_naive(f, g);
int N = max(len(f), len(g)), M = ceil(N, 2);
vc<T> f1, f2, g1, g2;
if (len(f) < M) f1 = f;
if (len(f) >= M) f1 = {f.begin(), f.begin() + M};
if (len(f) >= M) f2 = {f.begin() + M, f.end()};
if (len(g) < M) g1 = g;
if (len(g) >= M) g1 = {g.begin(), g.begin() + M};
if (len(g) >= M) g2 = {g.begin() + M, g.end()};
vc<T> a = conv_kara(f1, g1);
vc<T> b = conv_kara(f2, g2);
FOR(i, len(f2)) f1[i] += f2[i];
FOR(i, len(g2)) g1[i] += g2[i];
vc<T> c = conv_kara(f1, g1);
vc<T> F(len(f) + len(g) - 1);
FOR(i, len(a)) F[i] += a[i], c[i] -= a[i];
FOR(i, len(b)) F[2 * M + i] += b[i], c[i] -= b[i];
if (c.back() == T(0)) c.pop_back();
FOR(i, len(c)) if (c[i] != T(0)) F[M + i] += c[i];
return F;
}
TE vc<T> conv_ntt(vc<T> a, vc<T> b) {
assert(T::can_ntt());
if (a.empty() or b.empty()) return {};
int N = len(a), M = len(b), sz = 1;
while (sz < N + M - 1) sz <<= 1;
sh(a, sz), sh(b, sz);
bool ok = a == b;
ntt(a, 0);
if (ok) b = a;
else ntt(b, 0);
FOR(i, sz) a[i] *= b[i];
ntt(a, 1);
sh(a, N + M - 1);
return a;
}
TE vc<T> conv_mtt(const vc<T> &a, const vc<T> &b) {
int N = len(a), M = len(b);
if (not N or not M) return {};
static constexpr int p0 = 167772161;
static constexpr int p1 = 469762049;
static constexpr int p2 = 754974721;
using M0 = mint_t<p0>;
using M1 = mint_t<p1>;
using M2 = mint_t<p2>;
vc<M0> a0(N), b0(M);
vc<M1> a1(N), b1(M);
vc<M2> a2(N), b2(M);
FOR(i, N) a0[i] = a[i].val(), a1[i] = a[i].val(), a2[i] = a[i].val();
FOR(i, M) b0[i] = b[i].val(), b1[i] = b[i].val(), b2[i] = b[i].val();
vc<M0> c0 = conv_ntt<M0>(a0, b0);
vc<M1> c1 = conv_ntt<M1>(a1, b1);
vc<M2> c2 = conv_ntt<M2>(a2, b2);
vc<T> c(len(c0));
FOR(i, N + M - 1) c[i] = crt<T, p0, p1, p2>(c0[i].val(), c1[i].val(), c2[i].val());
return c;
}
TE vc<T> convolution(const vc<T> &a, const vc<T> &b) {
int N = len(a), M = len(b);
if (not N or not M) return {};
if (T::can_ntt()) {
if (min(N, M) <= 50) return conv_kara(a, b);
return conv_ntt(a, b);
}
if (min(N, M) <= 200) return conv_kara(a, b);
return conv_mtt(a, b);
}
#line 2 "YRS/po/bs.hpp"
#line 2 "YRS/po/c/inte.hpp"
#line 4 "YRS/po/c/inte.hpp"
// 不定积分
TE vc<T> inte(const vc<T> &f) {
int N = len(f);
vc<T> g(N + 1);
FOR(i, 1, N + 1) g[i] = f[i - 1] * inv<T>(i);
return g;
}
// 定积分
TE T inte(const vc<T> &f, T l, T r) {
T s = 0, L = 1, R = 1;
int N = len(f);
FOR(i, N) {
L *= l, R *= r;
s += inv<T>(i + 1) * f[i] * (L - R);
}
return s;
}
#line 2 "YRS/po/c/diff.hpp"
#line 4 "YRS/po/c/diff.hpp"
TE vc<T> diff(const vc<T> &f) {
int N = len(f);
if (N <= 1) return {};
vc<T> g(N - 1);
FOR(i, N - 1) g[i] = f[i + 1] * T(i + 1);
return g;
}
#line 6 "YRS/po/bs.hpp"
TE inline vc<T> &operator+=(vc<T> &a, const vc<T> &b) {
int N = len(b);
if (N > len(a)) sh(a, N);
FOR(i, N) a[i] += b[i];
return a;
}
TE inline vc<T> operator+(const vc<T> &a, const vc<T> &b) {
vc<T> c(a);
return c += b;
}
TE inline vc<T> &operator-=(vc<T> &a, const vc<T> &b) {
int N = len(b);
if (N > len(a)) sh(a, N);
FOR(i, N) a[i] -= b[i];
return a;
}
TE inline vc<T> operator-(const vc<T> &a, const vc<T> &b) {
vc<T> c(a);
return c -= b;
}
TE inline vc<T> operator*(const vc<T> &a, const vc<T> &b) {
return convolution(a, b);
}
#define D_poly() vc<mint> operator"" _p(ull x) { return vc<mint>{x}; } vc<mint> operator"" _p(const char *s, size_t le) {vc<mint> res;int sgn = 1, op = 0, coef = 0, ch = 0, sz = le;ll x = 0;Z re = [&](int i) {if (len(res) <= i) res.resize(i + 1);};Z cl = [&]() {if (op == -1) re(1), res[1] += sgn * coef;else if (op == 0) re(0), res[0] += sgn * (int)x;else if (op == 1) re(x), res[x] += sgn * coef;else assert(0);op = 0, x = 0, ch = 0;};FOR(i, sz) {if (s[i] == '+') cl(), sgn = 1;else if (s[i] == '-') cl(), sgn = -1;else if (isdigit(s[i])) {assert(op == 0 or op == 1);if (op == 0) ch = 1, x = (x * 10ll + s[i] - 48) % mint::get_mod();else x = x * 10ll + s[i] - 48, assert(x < 1e8);} else if (s[i] == 'x') {assert(s[i + 1] == '^' or s[i + 1] == '+' or s[i + 1] == '-' or s[i + 1] == 0);op = -1;coef = ch ? x : 1;x = 0;} else if (s[i] == '^') {assert(op == -1);op = 1;}}cl();return res; }
#line 5 "YRS/po/fps_inv.hpp"
// O(NK)
TE vc<T> fps_inv_sparse(const vc<T> &f) {
int N = len(f);
vc<pair<int, T>> dat;
FOR(i, 1, N) if (f[i] != T(0)) dat.ep(i, f[i]);
vc<T> g(N);
T t = T(1) / f[0];
g[0] = t;
FOR(i, 1, N) {
T s = 0;
for (Z &&[x, y] : dat) {
if (x > i) break;
s -= y * g[i - x];
}
g[i] = s * t;
}
return g;
}
TE vc<T> fps_inv_dense_ntt(const vc<T> &a) {
vc<T> s{T(1) / a[0]};
int N = len(a), n = 1;
s.reserve(N);
for (; n < N; n <<= 1) {
vc<T> f(n << 1), g(n << 1);
int L = min(N, n << 1);
FOR(i, L) f[i] = a[i];
FOR(i, n) g[i] = s[i];
ntt(f, 0);
ntt(g, 0);
FOR(i, n << 1) f[i] *= g[i];
ntt(f, 1);
FOR(i, n) f[i] = 0;
ntt(f, 0);
FOR(i, n << 1) f[i] *= g[i];
ntt(f, 1);
FOR(i, n, L) s.ep(-f[i]);
}
return s;
}
TE vc<T> fps_inv_dense(const vc<T> &a) {
if constexpr (T::can_ntt()) return fps_inv_dense_ntt(a);
int N = len(a), n = 1;
vc<T> R{T(1) / a[0]}, p;
while (n < N) {
p = R * R;
p.resize(n << 1);
vc<T> f = {a.begin(), a.begin() + min(n << 1, N)};
p = p * f;
sh(R, n << 1);
FOR(i, n << 1) R[i] = R[i] + R[i] - p[i];
n <<= 1;
}
sh(R, N);
return R;
}
TE vc<T> fps_inv(const vc<T> &f) {
assert(f[0] != T(0));
int sz = count_terms(f), c = T::can_ntt() ? 160 : 820;
return sz <= c ? fps_inv_sparse(f) : fps_inv_dense(f);
}
#line 5 "YRS/po/fps_div.hpp"
TE vc<T> fps_div_sprase(vc<T> f, vc<T> g) {
if (g[0] != T(1)) {
T c = g[0].inv();
for (Z &x : f) x *= c;
for (Z &x : g) x *= c;
}
vc<pair<int, T>> dat;
int N = len(g);
FOR(i, 1, N) if (g[i] != T(0)) dat.ep(i, -g[i]);
N = len(f);
FOR(i, N) for (Z [x, y] : dat) if (i >= x) f[i] += y * f[i - x];
return f;
}
TE vc<T> fps_div_dense_ntt(const vc<T> &f, const vc<T> &g) {
int N = len(f), M = len(g);
if (N == 1) return {f[0] / g[0]};
int m = 1;
while (m + m < N) m <<= 1;
vc<T> gs(g), a(m << 1), b(m << 1);
sh(gs, m);
gs = fps_inv(gs);
sh(gs, m << 1);
ntt(gs, 0);
FOR(i, m) a[i] = f[i];
FOR(i, m, N) a[i] = 0;
ntt(a, 0);
FOR(i, m << 1) a[i] *= gs[i];
ntt(a, 1);
vc<T> s(N);
FOR(i, m) s[i] = a[i];
FOR(i, m, m << 1) a[i] = 0;
ntt(a, 0);
FOR(i, min(m << 1, M)) b[i] = g[i];
FOR(i, min(m << 1, M), m << 1) b[i] = 0;
ntt(b, 0);
FOR(i, m << 1) a[i] *= b[i];
ntt(a, 1);
FOR(i, m) a[i] = 0;
FOR(i, m, min(m << 1, N)) a[i] -= f[i];
ntt(a, 0);
FOR(i, m << 1) a[i] *= gs[i];
ntt(a, 1);
FOR(i, m, N) s[i] -= a[i];
return s;
}
TE vc<T> fps_div_dense_mtt(vc<T> f, vc<T> g) {
int N = len(f);
sh(g, N);
g = fps_inv(g);
f = f * g;
sh(f, N);
return f;
}
// f/g 截断的商
TE vc<T> fps_div_dense(const vc<T> &f, const vc<T> &g) {
if (T::can_ntt()) return fps_div_dense_ntt(f, g);
return fps_div_dense_mtt(f, g);
}
TE vc<T> fps_div(const vc<T> &f, const vc<T> &g) {
if (count_terms(g) < 50) return fps_div_sprase(f, g);
return fps_div_dense(f, g);
}
#line 2 "YRS/po/c/ntt_db.hpp"
#line 2 "YRS/po/c/transposed_ntt.hpp"
template <typename mint>
void transposed_ntt(vc<mint> &a, bool in) {
assert(mint::can_ntt());
const int p = mint::ntt_info().fi;
const uint mod = mint::get_mod();
static array<mint, 30> r, ir, rt, irt, rat, irat;
assert(p != -1 and len(a) <= (1 << max(0, p)));
static bool ok = 0;
if (not ok) {
ok = 1;
r[p] = mint::ntt_info().se;
ir[p] = mint(1) / r[p];
FOR_R(i, p) {
r[i] = r[i + 1] * r[i + 1];
ir[i] = ir[i + 1] * ir[i + 1];
}
mint s = 1, in = 1;
FOR(i, p - 1) {
rt[i] = r[i + 2] * s;
irt[i] = ir[i + 2] * in;
s *= ir[i + 2];
in *= r[i + 2];
}
s = 1, in = 1;
FOR(i, p - 2) {
rat[i] = r[i + 3] * s;
irat[i] = ir[i + 3] * in;
s *= ir[i + 3];
in *= r[i + 3];
}
}
int N = len(a), n = topbit(N);
assert(N == 1 << n);
if (not in) {
int sz = n;
while (sz > 0) {
if (sz == 1) {
int p = 1 << (n - sz);
mint c = 1;
FOR(s, 1 << (sz - 1)) {
int of = s << (n - sz + 1);
FOR(i, p) {
ull l = a[i + of].val(), r = a[i + of + p].val();
a[i + of] = l + r, a[i + of + p] = (mod + l - r) * c.val();
}
c *= rt[topbit(~s & -~s)];
}
--sz;
} else {
int p = 1 << (n - sz);
mint c = 1, in = r[2];
FOR(s, 1 << (sz - 2)) {
int of = s << (n - sz + 2);
mint r2 = c * c, r3 = r2 * c;
FOR(i, p) {
ull a0 = a[i + of + 0 * p].val();
ull a1 = a[i + of + 1 * p].val();
ull a2 = a[i + of + 2 * p].val();
ull a3 = a[i + of + 3 * p].val();
ull x = (mod + a2 - a3) * in.val() % mod;
a[i + of] = a0 + a1 + a2 + a3;
a[i + of + 1 * p] = (a0 + mod - a1 + x) * c.val();
a[i + of + 2 * p] = (a0 + a1 + 2 * mod - a2 - a3) * r2.val();
a[i + of + 3 * p] = (a0 + 2 * mod - a1 - x) * r3.val();
}
c *= rat[topbit(~s & -~s)];
}
sz -= 2;
}
}
} else {
mint c = mint(1) / mint(len(a));
FOR(i, len(a)) a[i] *= c;
int sz = 0;
while (sz < n) {
if (sz == n - 1) {
int p = 1 << (n - sz - 1);
mint c = 1;
FOR(s, 1 << sz) {
int of = s << (n - sz);
FOR(i, p) {
mint l = a[i + of], r = a[i + of + p] * c;
a[i + of] = l + r, a[i + of + p] = l - r;
}
c *= irt[topbit(~s & -~s)];
}
++sz;
} else {
int p = 1 << (n - sz - 2);
mint c = 1, in = ir[2];
FOR(s, 1 << sz) {
mint r2 = c * c, r3 = r2 * c;
int of = s << (n - sz);
FOR(i, p) {
ull m2 = ull(mod) * mod;
ull a0 = a[i + of].val();
ull a1 = ull(a[i + of + p].val()) * c.val();
ull a2 = ull(a[i + of + 2 * p].val()) * r2.val();
ull a3 = ull(a[i + of + 3 * p].val()) * r3.val();
ull t = (a1 + m2 - a3) % mod * in.val();
ull na = m2 - a2;
a[i + of] = a0 + a1 + a2 + a3;
a[i + of + 1 * p] = a0 + a2 + (2 * m2 - a1 - a3);
a[i + of + 2 * p] = a0 + na + t;
a[i + of + 3 * p] = a0 + na + m2 - t;
}
c *= irat[topbit(~s & -~s)];
}
sz += 2;
}
}
}
}
#line 5 "YRS/po/c/ntt_db.hpp"
template <typename mint, bool transposed = 0>
void ntt_db(vc<mint> &a) {
static array<mint, 30> rt;
static bool ok = 0;
if (not ok) {
ok = 1;
const int s = mint::ntt_info().fi;
rt[s] = mint::ntt_info().se;
FOR_R(i, s) rt[i] = rt[i + 1] * rt[i + 1];
}
if (not transposed) {
int N = len(a);
Z b = a;
ntt(b, 1);
mint r = 1, z = rt[topbit(N << 1)];
FOR(i, N) b[i] *= r, r *= z;
ntt(b, 0);
copy(all(b), back_inserter(a));
} else {
int N = len(a) >> 1;
vc<mint> t{a.begin(), a.begin() + N};
a = {a.begin() + N, a.end()};
transposed_ntt(a, 0);
mint r = 1, z = rt[topbit(N << 1)];
FOR(i, N) a[i] *= r, r *= z;
transposed_ntt(a, 1);
FOR(i, N) a[i] += t[i];
}
}
#line 2 "YRS/po/poly_divmod.hpp"
#line 4 "YRS/po/poly_divmod.hpp"
TE pair<vc<T>, vc<T>> poly_divmod(vc<T> f, vc<T> g) {
assert(g.back() != 0);
int N = len(f), M = len(g);
if (N < M) return {{}, f};
vc<T> ff = f, gg = g;
reverse(ff);
reverse(gg);
int d = N - M + 1;
sh(ff, d);
sh(gg, d);
gg = fps_inv(gg);
vc<T> q = ff * gg;
sh(q, d);
reverse(q);
vc<T> c = q * g;
FOR(i, N) f[i] -= c[i];
while (not f.empty() and f.back() == 0) f.pop_back();
return {q, f};
}
#line 6 "YRS/po/coef_of_rational_fps.hpp"
TE T coef_of_rational_fps_ntt(vc<T> p, vc<T> q, ll N) {
assert(0 <= len(p) and len(p) + 1 == len(q) and q[0] == T(1));
if (p.empty()) return 0;
int n = 1;
while (n < len(q)) n <<= 1;
vc<T> w(n);
vc<int> b(n);
int lg = topbit(n);
FOR(i, n) b[i] = (b[i >> 1] >> 1) + ((i & 1) << (lg - 1));
const int t = T::ntt_info().fi;
const T r = T::ntt_info().se;
T s = r.inv().pow((1 << t) / (n << 1)), c = T(2).inv();
for (int i : b) w[i] = c, c *= s;
sh(p, n << 1);
sh(q, n << 1);
ntt(p, 0), ntt(q, 0);
while (N >= n) {
if (not(N & 1)) {
FOR(i, n) {
p[i] = (p[i << 1] * q[i << 1 | 1] + p[i << 1 | 1] * q[i << 1]) * T(2).inv();
}
} else {
FOR(i, n) {
p[i] = (p[i << 1] * q[i << 1 | 1] - p[i << 1 | 1] * q[i << 1]) * w[i];
}
}
FOR(i, n) q[i] = q[i << 1] * q[i << 1 | 1];
sh(p, n);
sh(q, n);
N >>= 1;
if (N < n) break;
ntt_db(p), ntt_db(q);
}
ntt(p, 1), ntt(q, 1);
q = fps_inv(q);
T ans = 0;
FOR(i, N + 1) ans += p[i] * q[N - i];
return ans;
}
TE T coef_of_rational_fps_mtt(vc<T> p, vc<T> q, ll N) {
assert(0 <= len(p) and len(p) + 1 == len(q) and q[0] == T(1));
if (p.empty()) return 0;
while (N >= len(p)) {
vc<T> qq = q;
FOR(i, len(qq)) if (i & 1) qq[i] = -qq[i];
p = p * qq;
q = q * qq;
FOR(i, len(qq)) q[i] = q[i << 1];
FOR(i, len(qq) - 1) p[i] = p[i << 1 | (N & 1)];
sh(p, len(qq) - 1);
sh(q, len(qq));
N >>= 1;
}
return fps_div(p, q)[N];
}
// [x^N]P/Q 求 ai=sum ci ai-j 则是 p / {1, -c1, -c2}
TE T coef_of_rational_fps(vc<T> p, vc<T> q, ll N) {
if (p.empty()) return {};
assert(len(q) > 0 and q[0] != T(0));
while (q.back() == T(0)) q.pop_back();
T c = T(1) / q[0];
for (T &x : p) x *= c;
for (T &x : q) x *= c;
T bs = 0;
if (len(p) >= len(q)) {
Z [f, g] = poly_divmod(p, q);
bs = (N < len(f) ? f[N] : T(0));
p = g;
}
sh(p, len(q) - 1);
if (T::can_ntt()) return bs + coef_of_rational_fps_ntt(p, q, N);
return bs + coef_of_rational_fps_mtt(p, q, N);
}
#line 2 "YRS/po/find_line.hpp"
// a 的最短线性递推, for i >= k : a[i] = -sum(j : 0...N) c[j] * a[i - j]
TE vc<T> find_line(const vc<T> &a) {
int N = len(a);
vc<T> b{1}, c{1};
int l = 0, m = 1;
T p = 1;
FOR(i, N) {
T d = a[i];
FOR(k, 1, l + 1) d += c[k] * a[i - k];
if (d == T(0)) {
++m;
continue;
}
Z t = c;
T q = d / p;
if (len(c) < len(b) + m) c.insert(c.end(), len(b) + m - len(c), 0);
FOR(k, len(b)) c[k + m] -= q * b[k];
if (l + l <= i) {
b = t, l = i + 1 - l, m = 1, p = d;
} else ++m;
}
return c;
}
#line 6 "YRS/po/line_inte.hpp"
// 线性递推插值 iota
TE T line_inte(vc<T> a, ll N, int of = 0) {
if (N < len(a)) return a[N];
if (of) a = {a.begin() + of, a.end()};
N -= of;
vc<T> g = find_line(a), f = a * g;
sh(f, len(g) - 1);
return coef_of_rational_fps(f, g, N);
}
#line 12 "No_194_\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u5217\u306e\u7406\u89e3_1.cpp"
using mint = M17;
using DS = range_sum_point_add<monoid_add<mint>>;
void Yorisou() {
LL(N, K);
--K;
VEC(mint, a, N);
sh(a, N + N + 2);
DS seg(a);
FOR(i, N, N + N + 2) seg.multiply(i, seg.prod(i - N, i));
a = seg.get_all();
print(line_inte(a, K), line_inte(pre_sum<0>(a), K));
}
constexpr int tests = 0, fl = 0, DB = 10;
#line 1 "YRS/aa/main.hpp"
int main() {
cin.tie(0)->sync_with_stdio(0);
int T = 1;
if (fl) cerr.tie(0);
if (tests and not fl) IN(T);
for (int i = 0; i < T or fl; ++i) {
Yorisou();
if (fl and i % DB == 0) cerr << "Case: " << i << '\n';
}
return 0;
}
#line 27 "No_194_\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u5217\u306e\u7406\u89e3_1.cpp"