Submit Info #67581

Problem Lang User Status Time Memory
Polynomial Taylor Shift cpp hari64 AC 174 ms 52.47 MiB

ケース詳細
Name Status Time Memory
example_00 AC 1 ms 0.45 MiB
example_01 AC 1 ms 0.45 MiB
fft_killer_00 AC 174 ms 52.46 MiB
fft_killer_01 AC 174 ms 52.47 MiB
max_random_00 AC 173 ms 52.46 MiB
max_random_01 AC 173 ms 52.46 MiB
medium_00 AC 1 ms 0.57 MiB
medium_01 AC 2 ms 0.95 MiB
medium_02 AC 2 ms 1.01 MiB
medium_all_zero_00 AC 1 ms 0.57 MiB
medium_c_zero_00 AC 1 ms 0.57 MiB
random_00 AC 148 ms 43.26 MiB
random_01 AC 159 ms 48.21 MiB
random_02 AC 19 ms 6.04 MiB
small_00 AC 1 ms 0.45 MiB
small_01 AC 1 ms 0.45 MiB
small_02 AC 1 ms 0.45 MiB
small_03 AC 1 ms 0.45 MiB
small_04 AC 1 ms 0.45 MiB
small_05 AC 1 ms 0.45 MiB
small_06 AC 1 ms 0.45 MiB
small_07 AC 1 ms 0.45 MiB
small_08 AC 1 ms 0.45 MiB
small_09 AC 1 ms 0.45 MiB
small_10 AC 1 ms 0.45 MiB
small_11 AC 1 ms 0.45 MiB
small_12 AC 1 ms 0.45 MiB
small_13 AC 1 ms 0.41 MiB
small_14 AC 1 ms 0.45 MiB
small_15 AC 1 ms 0.45 MiB

#include <bits/stdc++.h> // clang-format off using namespace std;constexpr int INF=1001001001;constexpr long long INFll=1001001001001001001;namespace viewer{template <class T>string f(T i){string s=(i==INF||i==INFll?"inf":to_string(i));s=string(max(0,3-int(s.size())),' ')+s;return s;} template<class T>auto v(T&x,string end)->decltype(cerr<<x){return cerr<<x<<end;}void v(int x,string end){cerr<<f(x)<<end;}void v(long long x,string end){cerr<<f(x)<<end;}void v(float x,string end){cerr<<fixed<<setprecision(16)<<x<<end;}void v(double x,string end){cerr<<fixed<<setprecision(16)<<x<<end;}void v(long double x,string end){cerr<<fixed<<setprecision(16)<<x<<end;} template<class T,class U>void v(const pair<T,U>&p,string end="\n"){cerr<<"(";v(p.first,", ");v(p.second,")"+end);}template<class T,class U>void v(const tuple<T,U>&t,string end="\n"){auto[a,b]=t;cerr<<"(";v(a,", ");v(b,")"+end);}template<class T,class U,class V>void v(const tuple<T,U,V>&t,string end="\n"){auto[a,b,c]=t;cerr<<"(";v(a,", ");v(b,", ");v(c,")"+end);}template<class T,class U,class V,class W>void v(const tuple<T,U,V,W>&t,string end="\n"){auto[a,b,c,d]=t;cerr<<"(";v(a,", ");v(b,", ");v(c,", ");v(d,")"+end);} template<class T>void v(const vector<T>&vx,string);template<class T>auto ve(int,const vector<T>&vx)->decltype(cerr<<vx[0]){cerr<<"{";for(const T&x:vx)v(x,",");return cerr<<"}\n";}template <class T>auto ve(bool,const vector<T> &vx){cerr << "{\n";for(const T&x:vx)cerr<<" ",v(x,",");cerr<<"}\n";}template<class T>void v(const vector<T>&vx, string){ve(0,vx);} template<class T>void v(const set<T>&s,string e){vector<T>z(s.begin(),s.end());v(z,e);}template<class T>void v(const multiset<T>&s,string e){vector<T>z(s.begin(),s.end());v(z,e);}template<class T>void v(const unordered_set<T>&s,string e){vector<T>z(s.begin(),s.end());v(z,e);}template<class T>void v(const deque<T>&s,string e){vector<T>z(s.begin(),s.end());v(z,e);}template<class T>void v(const priority_queue<T>&p,string e){priority_queue<T>q=p;vector<T>z;while(!q.empty()){z.push_back(q.top());q.pop();}v(z,e);} template<class T,class U>void v(const map<T, U>&m,string e){cerr<<"{"<<(m.empty()?"":"\n");for(const auto&kv:m){cerr<<" [";v(kv.first,"");cerr<<"] : ";v(kv.second,"");cerr<<"\n";}cerr<<"}"+e;} template<class T>void _view(int n,string s,T&var){cerr<<"\033[1;32m"<<n<<"\033[0m: \033[1;36m"<<s<<"\033[0m = ";v(var,"\n");}template<class T>void grid(T _){}void grid(const vector<vector<bool>>&vvb){cerr<<"\n";for(const vector<bool>&vb:vvb){for(const bool&b:vb)cerr<<(b?".":"#");cerr<<"\n";}} void _debug(int, string){}template<typename H,typename... T>void _debug(int n,string S,H h,T... t){int i=0,cnt=0;for(;i<int(S.size());i++){if(S[i]=='(')cnt++;if(S[i]==')')cnt--;if(cnt==0&&S[i]==',')break;}if(i==int(S.size()))i=-1;if(i==-1)_view(n,S,h);else {string s1=S.substr(0,i);string s2=S.substr(i+2);if(s2=="\"grid\"")cerr<<n<<": "<<s1<<" = ",grid(h);else _view(n,s1,h),_debug(n,s2,t...);}}} template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}template<class T>bool chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;} #ifdef ONLINE_JUDGE #define debug(...) #else #define debug(...)viewer::_debug(__LINE__,#__VA_ARGS__,__VA_ARGS__) #endif // clang-format on // clang-format off // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a template<int MOD> struct Fp{long long val;constexpr Fp(long long v=0)noexcept:val(v%MOD){if(val<0)val+=MOD;}static constexpr int getmod(){return MOD;}constexpr Fp operator-()const noexcept{return val?MOD-val:0;} constexpr Fp operator+(const Fp&r)const noexcept{return Fp(*this)+=r;}constexpr Fp operator-(const Fp&r)const noexcept{return Fp(*this)-=r;}constexpr Fp operator*(const Fp&r)const noexcept{return Fp(*this)*=r;}constexpr Fp operator/(const Fp&r)const noexcept{return Fp(*this)/=r;} constexpr Fp operator++(int)noexcept{val+=1;if(val>=MOD)val-=MOD;return*this;}constexpr Fp operator--(int)noexcept{val-=1;if(val<0)val+=MOD;return*this;} constexpr Fp&operator+=(const Fp&r)noexcept{val+=r.val;if(val>=MOD)val-=MOD;return*this;}constexpr Fp&operator-=(const Fp&r)noexcept{val-=r.val;if(val<0)val+=MOD;return*this;}constexpr Fp&operator*=(const Fp&r)noexcept{val=val*r.val%MOD;return*this;}constexpr Fp&operator/=(const Fp&r)noexcept{long long a=r.val,b=MOD,u=1,v=0;while(b){long long t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}val=val*u%MOD;if(val<0)val+=MOD;return*this;} constexpr bool operator<(const Fp&r)const noexcept{return this->val<r.val;}constexpr bool operator>(const Fp&r)const noexcept{return this->val>r.val;}constexpr bool operator<=(const Fp&r)const noexcept{return this->val<=r.val;}constexpr bool operator>=(const Fp&r)const noexcept{return this->val>=r.val;}constexpr bool operator==(const Fp&r)const noexcept{return this->val==r.val;}constexpr bool operator!=(const Fp&r)const noexcept{return this->val!=r.val;} friend constexpr ostream& operator<<(ostream&os,const Fp<MOD>&x)noexcept{return os<<x.val;}};using mint=Fp<998244353>;vector<mint>mod_factorial={mint(1)}; mint modpow(mint base,long long exp){mint ret=1;if(base==0&&exp==0)cerr<<"\033[1;31mWARNING: 0^0 is a mathematical expression with no agreed-upon value.\033[0m"<<endl;while(exp>0){if(exp&1)ret*=base;base*=base;exp>>=1;}return ret;} mint modinv(mint base)noexcept{return modpow(base,base.getmod()-2);} /*mod must be a prime number*/mint modsqrt(mint a){long long p=mint::getmod();if(a<2)return a;if(modpow(a,(p-1)>>1)!=1)return -1;mint b=1,one=1;while(modpow(b,(p-1)>>1)==1)b+=one;long long m=p-1,e=0;while(m%2==0)m>>=1,e++;mint x=modpow(a,(m-1)>>1);mint y=a*x*x;x*=a;mint z=modpow(b,m);while(y!=1){long long j=0;mint t=y;while(t!=one)j++,t*=t;z=modpow(z,1ll<<(e-j-1));x*=z;z*=z;y*=z;e=j;}return x;} /*min x s.t. a^x ≡ b (mod m) or -1*/mint modlog(mint a, mint b){long long m=mint::getmod();long long lo=-1,hi=m;while(hi-lo>1){long long mi=(lo+hi)>>1;if(mi*mi>=m)hi=mi;else lo=mi;}long long sqrtM=hi;map<mint,long long>apow;mint rem=a;for(long long r=1;r<sqrtM;r++){if(apow.find(rem)==apow.end())apow[rem]=r;rem*=a;}mint A=modpow(modinv(a),sqrtM);rem=b;for(mint q=0;q<sqrtM;q++){if(rem==1&&q>0)return q*sqrtM;if(apow.find(rem)!=apow.end())return q*sqrtM+apow[rem];rem*=A;}return -1;} mint modfact(int n){if(int(mod_factorial.size())<=n){for(int i=mod_factorial.size();i<=n;i++){mint next=mod_factorial.back()*i;mod_factorial.push_back(next);}}return mod_factorial[n];} mint nCk(int n,int k){if(k<0||n<k)return mint(0);return modfact(n)*modinv(modfact(k))*modinv(modfact(n-k));} // clang-format on // clang-format off // https://ei1333.github.io/library/math/fps/formal-power-series-friendly-ntt.cpp struct NumberTheoreticTransformFriendlyModInt { static vector<mint> roots, iroots, rate3, irate3; static int max_base; NumberTheoreticTransformFriendlyModInt() = default; static void init() { if (roots.empty()) { const unsigned mod = mint::getmod(); assert(mod >= 3 && mod % 2 == 1); auto tmp = mod - 1; max_base = 0; while (tmp % 2 == 0) tmp >>= 1, max_base++; mint root = 2; while (modpow(root, (mod - 1) >> 1) == 1) root += 1; assert(modpow(root, mod - 1) == 1); roots.resize(max_base + 1); iroots.resize(max_base + 1); rate3.resize(max_base + 1); irate3.resize(max_base + 1); roots[max_base] = modpow(root, (mod - 1) >> max_base); iroots[max_base] = mint(1) / roots[max_base]; for (int i = max_base - 1; i >= 0; i--) { roots[i] = roots[i + 1] * roots[i + 1]; iroots[i] = iroots[i + 1] * iroots[i + 1]; } { mint prod = 1, iprod = 1; for (int i = 0; i <= max_base - 3; i++) { rate3[i] = roots[i + 3] * prod; irate3[i] = iroots[i + 3] * iprod; prod *= iroots[i + 3]; iprod *= roots[i + 3]; } } } } static void ntt(vector<mint> &a) { init(); const int n = (int)a.size(); assert((n & (n - 1)) == 0); int h = __builtin_ctz(n); assert(h <= max_base); int len = 0; mint imag = roots[2]; if (h & 1) { int p = 1 << (h - 1); // mint rot = 1; 注記:元のライブラリではコメントアウトされず for (int i = 0; i < p; i++) { auto r = a[i + p]; a[i + p] = a[i] - r; a[i] += r; } len++; } for (; len + 1 < h; len += 2) { int p = 1 << (h - len - 2); { // s = 0 for (int i = 0; i < p; i++) { auto a0 = a[i]; auto a1 = a[i + p]; auto a2 = a[i + 2 * p]; auto a3 = a[i + 3 * p]; auto a1na3imag = (a1 - a3) * imag; auto a0a2 = a0 + a2; auto a1a3 = a1 + a3; auto a0na2 = a0 - a2; a[i] = a0a2 + a1a3; a[i + 1 * p] = a0a2 - a1a3; a[i + 2 * p] = a0na2 + a1na3imag; a[i + 3 * p] = a0na2 - a1na3imag; } } mint rot = rate3[0]; for (int s = 1; s < (1 << len); s++) { int offset = s << (h - len); mint rot2 = rot * rot; mint rot3 = rot2 * rot; for (int i = 0; i < p; i++) { auto a0 = a[i + offset]; auto a1 = a[i + offset + p] * rot; auto a2 = a[i + offset + 2 * p] * rot2; auto a3 = a[i + offset + 3 * p] * rot3; auto a1na3imag = (a1 - a3) * imag; auto a0a2 = a0 + a2; auto a1a3 = a1 + a3; auto a0na2 = a0 - a2; a[i + offset] = a0a2 + a1a3; a[i + offset + 1 * p] = a0a2 - a1a3; a[i + offset + 2 * p] = a0na2 + a1na3imag; a[i + offset + 3 * p] = a0na2 - a1na3imag; } rot *= rate3[__builtin_ctz(~s)]; } } } static void intt(vector<mint> &a, bool f = true) { init(); const int n = (int)a.size(); assert((n & (n - 1)) == 0); int h = __builtin_ctz(n); assert(h <= max_base); int len = h; mint iimag = iroots[2]; for (; len > 1; len -= 2) { int p = 1 << (h - len); { // s = 0 for (int i = 0; i < p; i++) { auto a0 = a[i]; auto a1 = a[i + 1 * p]; auto a2 = a[i + 2 * p]; auto a3 = a[i + 3 * p]; auto a2na3iimag = (a2 - a3) * iimag; auto a0na1 = a0 - a1; auto a0a1 = a0 + a1; auto a2a3 = a2 + a3; a[i] = a0a1 + a2a3; a[i + 1 * p] = (a0na1 + a2na3iimag); a[i + 2 * p] = (a0a1 - a2a3); a[i + 3 * p] = (a0na1 - a2na3iimag); } } mint irot = irate3[0]; for (int s = 1; s < (1 << (len - 2)); s++) { int offset = s << (h - len + 2); mint irot2 = irot * irot; mint irot3 = irot2 * irot; for (int i = 0; i < p; i++) { auto a0 = a[i + offset]; auto a1 = a[i + offset + 1 * p]; auto a2 = a[i + offset + 2 * p]; auto a3 = a[i + offset + 3 * p]; auto a2na3iimag = (a2 - a3) * iimag; auto a0na1 = a0 - a1; auto a0a1 = a0 + a1; auto a2a3 = a2 + a3; a[i + offset] = a0a1 + a2a3; a[i + offset + 1 * p] = (a0na1 + a2na3iimag) * irot; a[i + offset + 2 * p] = (a0a1 - a2a3) * irot2; a[i + offset + 3 * p] = (a0na1 - a2na3iimag) * irot3; } irot *= irate3[__builtin_ctz(~s)]; } } if (len >= 1) { int p = 1 << (h - 1); for (int i = 0; i < p; i++) { auto ajp = a[i] - a[i + p]; a[i] += a[i + p]; a[i + p] = ajp; } } if (f) { mint inv_sz = mint(1) / n; for (int i = 0; i < n; i++) a[i] *= inv_sz; } } static vector<mint> multiply(vector<mint> a, vector<mint> b) { int need = a.size() + b.size() - 1; int nbase = 1; while ((1 << nbase) < need) nbase++; int sz = 1 << nbase; a.resize(sz, 0); b.resize(sz, 0); ntt(a); ntt(b); mint inv_sz = mint(1) / sz; for (int i = 0; i < sz; i++) a[i] *= b[i] * inv_sz; intt(a, false); a.resize(need); return a; } }; vector<mint> NumberTheoreticTransformFriendlyModInt::roots = vector<mint>(); vector<mint> NumberTheoreticTransformFriendlyModInt::iroots = vector<mint>(); vector<mint> NumberTheoreticTransformFriendlyModInt::rate3 = vector<mint>(); vector<mint> NumberTheoreticTransformFriendlyModInt::irate3 = vector<mint>(); int NumberTheoreticTransformFriendlyModInt::max_base = 0; template <typename T> struct FormalPowerSeriesFriendlyNTT : vector<T> { using vector<T>::vector; using P = FormalPowerSeriesFriendlyNTT; using NTT = NumberTheoreticTransformFriendlyModInt; P pre(int deg)const{return P(begin(*this),begin(*this)+min((int)this->size(),deg));} P rev(int deg=-1)const{P ret(*this);if(deg!=-1)ret.resize(deg,T(0));reverse(begin(ret),end(ret));return ret;} void shrink(){while(this->size()&&this->back()==T(0))this->pop_back();} P operator+(const P&r)const{return P(*this)+=r;} P operator+(const T&v)const{return P(*this)+=v;} P operator-(const P&r)const{return P(*this)-=r;} P operator-(const T&v)const{return P(*this)-=v;} P operator*(const P&r)const{return P(*this)*=r;} P operator*(const T&v)const{return P(*this)*=v;} P operator/(const P&r)const{return P(*this)/=r;} P operator%(const P&r)const{return P(*this)%=r;} P &operator+=(const P&r){if(r.size()>this->size())this->resize(r.size());for(int i=0;i<(int)r.size();i++)(*this)[i]+=r[i];return*this;} P &operator-=(const P&r){if(r.size()>this->size())this->resize(r.size());for(int i=0;i<(int)r.size();i++)(*this)[i]-=r[i];return*this;} // https://judge.yosupo.jp/problem/convolution_mod P &operator*=(const P&r){if(this->empty()||r.empty()){this->clear();return*this;}auto ret=NTT::multiply(*this,r);return*this={begin(ret),end(ret)};} P &operator/=(const P&r){if(this->size()<r.size()){this->clear();return*this;}int n=this->size()-r.size()+1;return*this=(rev().pre(n)*r.rev().inv(n)).pre(n).rev(n);} P &operator%=(const P&r){*this-=*this/r*r;shrink();return*this;} // https://judge.yosupo.jp/problem/division_of_polynomials pair<P,P>div_mod(const P&r) {P q=*this/r;P x=*this-q*r;x.shrink();return make_pair(q,x);} P operator-()const{P ret(this->size());for(int i=0;i<(int)this->size();i++)ret[i]=-(*this)[i];return ret;} P&operator+=(const T&r){if(this->empty())this->resize(1);(*this)[0]+=r;return*this;} P&operator-=(const T&r){if(this->empty())this->resize(1);(*this)[0]-=r;return*this;} P&operator*=(const T&v){for(int i=0;i<(int)this->size();i++)(*this)[i]*=v;return*this;} P dot(P r)const{P ret(min(this->size(),r.size()));for(int i=0;i<(int)ret.size();i++)ret[i]=(*this)[i]*r[i];return ret;} P operator>>(int sz)const{if((int)this->size()<=sz)return{};P ret(*this);ret.erase(ret.begin(),ret.begin()+sz);return ret;} P operator<<(int sz)const{P ret(*this);ret.insert(ret.begin(), sz, T(0));return ret;} //operator(x): f(x)の値を評価して返す O(n) T operator()(T x) const{T r=0,w=1;for(auto&v:*this){r+=w*v;w*=x;}return r;} // diff(): f'(x)を返す O(n) P diff() const { const int n = (int)this->size(); P ret(max(0, n - 1)); for (int i = 1; i < n; i++) ret[i - 1] = (*this)[i] * T(i); return ret; } // integral(): ∫f(x)dxを返す O(n) P integral() const { const int n = (int)this->size(); P ret(n + 1); ret[0] = T(0); for (int i = 0; i < n; i++) ret[i + 1] = (*this)[i] / T(i + 1); return ret; } // inv(): 1/f(x)を返す f(0)!=0を要求する deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/inv_of_formal_power_series P inv(int deg = -1) const { assert(((*this)[0]) != T(0)); const int n = (int)this->size(); if (deg == -1) deg = n; P res(deg); res[0] = {T(1) / (*this)[0]}; for (int d = 1; d < deg; d <<= 1) { P f(2 * d), g(2 * d); for (int j = 0; j < min(n, 2 * d); j++) f[j] = (*this)[j]; for (int j = 0; j < d; j++) g[j] = res[j]; NTT::ntt(f); NTT::ntt(g); f = f.dot(g); NTT::intt(f); for (int j = 0; j < d; j++) f[j] = 0; NTT::ntt(f); for (int j = 0; j < 2 * d; j++) f[j] *= g[j]; NTT::intt(f); for (int j = d; j < min(2 * d, deg); j++) res[j] = -f[j]; } return res; } // log(): logf(x)を返す f(0)==1を要求する deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/log_of_formal_power_series P log(int deg = -1) const { assert((*this)[0] == T(1)); const int n = (int)this->size(); if (deg == -1) deg = n; return (this->diff() * this->inv(deg)).pre(deg - 1).integral(); } // sqrt(): √f(x)(i.e. g(x) s.t. g(x)*g(x)==f(x))を返す 存在しない場合は空配列を返す deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/sqrt_of_formal_power_series P sqrt(int deg = -1, const function<T(T)> &get_sqrt = [](T y) { return modsqrt(y); }) const { const int n = (int)this->size(); if (deg == -1) deg = n; if ((*this)[0] == T(0)) { for (int i = 1; i < n; i++) { if ((*this)[i] != T(0)) { if (i & 1) return {}; if (deg - i / 2 <= 0) break; auto ret = (*this >> i).sqrt(deg - i / 2, get_sqrt); if (ret.empty()) return {}; ret = ret << (i / 2); if ((int)ret.size() < deg) ret.resize(deg, T(0)); return ret; } } return P(deg, 0); } auto sqr = T(get_sqrt((*this)[0])); if (sqr * sqr != (*this)[0]) return {}; P ret{sqr}; T inv2 = T(1) / T(2); for (int i = 1; i < deg; i <<= 1) { ret = (ret + pre(i << 1) * ret.inv(i << 1)) * inv2; } return ret.pre(deg); } P sqrt(const function<T(T)> &get_sqrt, int deg = -1) const { return sqrt(deg, get_sqrt); } // exp(): exp(f(x))を返す f(0)=0を要求する deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/exp_of_formal_power_series P exp(int deg = -1) const { if (deg == -1) deg = this->size(); assert((*this)[0] == T(0)); P inv; inv.reserve(deg + 1); inv.push_back(T(0)); inv.push_back(T(1)); auto inplace_integral = [&](P &F) -> void { const int n = (int)F.size(); auto mod = T::getmod(); while ((int)inv.size() <= n) { int i = inv.size(); inv.push_back((-inv[mod % i]) * (mod / i)); } F.insert(begin(F), T(0)); for (int i = 1; i <= n; i++) F[i] *= inv[i]; }; auto inplace_diff = [](P &F) -> void { if (F.empty()) return; F.erase(begin(F)); T coeff = 1, one = 1; for (int i = 0; i < (int)F.size(); i++) { F[i] *= coeff; coeff += one; } }; P b{1, 1 < (int)this->size() ? (*this)[1] : 0}, c{1}, z1, z2{1, 1}; for (int m = 2; m < deg; m *= 2) { auto y = b; y.resize(2 * m); NTT::ntt(y); z1 = z2; P z(m); for (int i = 0; i < m; ++i) z[i] = y[i] * z1[i]; NTT::intt(z); fill(begin(z), begin(z) + m / 2, T(0)); NTT::ntt(z); for (int i = 0; i < m; ++i) z[i] *= -z1[i]; NTT::intt(z); c.insert(end(c), begin(z) + m / 2, end(z)); z2 = c; z2.resize(2 * m); NTT::ntt(z2); P x(begin(*this), begin(*this) + min<int>(this->size(), m)); inplace_diff(x); x.push_back(T(0)); NTT::ntt(x); for (int i = 0; i < m; ++i) x[i] *= y[i]; NTT::intt(x); x -= b.diff(); x.resize(2 * m); for (int i = 0; i < m - 1; ++i) x[m + i] = x[i], x[i] = T(0); NTT::ntt(x); for (int i = 0; i < 2 * m; ++i) x[i] *= z2[i]; NTT::intt(x); x.pop_back(); inplace_integral(x); for (int i = m; i < min<int>(this->size(), 2 * m); ++i) x[i] += (*this)[i]; fill(begin(x), begin(x) + m, T(0)); NTT::ntt(x); for (int i = 0; i < 2 * m; ++i) x[i] *= y[i]; NTT::intt(x); b.insert(end(b), begin(x) + m, end(x)); } return P{begin(b), begin(b) + deg}; } // pow(k): f^k(x)を返す deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/pow_of_formal_power_series P pow(int64_t k, int deg = -1) const { const int n = (int)this->size(); if (deg == -1) deg = n; for (int i = 0; i < n; i++) { if ((*this)[i] != T(0)) { T rev = T(1) / (*this)[i]; P ret = (((*this * rev) >> i).log() * k).exp() * (modpow((*this)[i],k)); if (i * k > deg) return P(deg, T(0)); ret = (ret << (i * k)).pre(deg); if ((int)ret.size() < deg) ret.resize(deg, T(0)); return ret; } } return *this; } // mod_pow(k,g): f^k(x) (mod g(x))を返す O(nlogklogdeg(f)) P mod_pow(int64_t k, P g) const { P modinv = g.rev().inv(); auto get_div = [&](P base) { if (base.size() < g.size()) { base.clear(); return base; } int n = base.size() - g.size() + 1; return (base.rev().pre(n) * modinv.pre(n)).pre(n).rev(n); }; P x(*this), ret{1}; while (k > 0) { if (k & 1) { ret *= x; ret -= get_div(ret) * g; ret.shrink(); } x *= x; x -= get_div(x) * g; x.shrink(); k >>= 1; } return ret; } //taylor_shift(c): g(x)=f(x+c)を満たすg(x)を返す // https://judge.yosupo.jp/problem/polynomial_taylor_shift P taylor_shift(T c) const { int n = (int)this->size(); vector<T> fact(n), rfact(n); fact[0] = rfact[0] = T(1); for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * T(i); rfact[n - 1] = T(1) / fact[n - 1]; for (int i = n - 1; i > 1; i--) rfact[i - 1] = rfact[i] * T(i); P p(*this); for (int i = 0; i < n; i++) p[i] *= fact[i]; p = p.rev(); P bs(n, T(1)); for (int i = 1; i < n; i++) bs[i] = bs[i - 1] * c * rfact[i] * fact[i - 1]; p = (p * bs).pre(n); p = p.rev(); for (int i = 0; i < n; i++) p[i] *= rfact[i]; return p; } }; // clang-format on using FPS = FormalPowerSeriesFriendlyNTT<mint>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int M; cin >> M; vector<mint> As(N); for (int i = 0; i < N; i++) { int a; cin >> a; As[i] = a; } FPS fps_A(As.begin(), As.end()); FPS ans = fps_A.taylor_shift(M); for (int i = 0; i < (int)ans.size(); i++) { cout << ans[i] << " "; } cout << endl; return 0; }