// BEGIN: main.cpp #line 1 "main.cpp" #include using namespace std; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) using ll=long long; using u32=unsigned int; using u64=unsigned long long; using i128=__int128; using u128=unsigned __int128; using f128=__float128; using pii=pair; using pll=pair; template using vc=vector; template using vvc=vc>; template using vvvc=vc>; using vi=vc; using vll=vc; using vvi=vc; using vvll=vc; #define vv(type,name,n,...) \ vector> name(n,vector(__VA_ARGS__)) #define vvv(type,name,n,m,...) \ vector>> name(n,vector>(m,vector(__VA_ARGS__))) template using min_heap=priority_queue,greater>; template using max_heap=priority_queue; // https://trap.jp/post/1224/ #define rep1(n) for(ll i=0; i<(ll)(n); ++i) #define rep2(i,n) for(ll i=0; i<(ll)(n); ++i) #define rep3(i,a,b) for(ll i=(ll)(a); i<(ll)(b); ++i) #define rep4(i,a,b,c) for(ll i=(ll)(a); i<(ll)(b); i+=(c)) #define cut4(a,b,c,d,e,...) e #define rep(...) cut4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define per1(n) for(ll i=((ll)n)-1; i>=0; --i) #define per2(i,n) for(ll i=((ll)n)-1; i>=0; --i) #define per3(i,a,b) for(ll i=((ll)a)-1; i>=(ll)(b); --i) #define per4(i,a,b,c) for(ll i=((ll)a)-1; i>=(ll)(b); i-=(c)) #define per(...) cut4(__VA_ARGS__,per4,per3,per2,per1)(__VA_ARGS__) #define rep_subset(i,s) for(ll i=(s); i>=0; i=(i==0?-1:(i-1)&(s))) template constexpr T ifloor(const T a, const S b){return a/b-(a%b&&(a^b)<0);} template constexpr T iceil(const T a, const S b){return ifloor(a+b-1,b);} template void sort_unique(vector &vec){ sort(vec.begin(),vec.end()); vec.resize(unique(vec.begin(),vec.end())-vec.begin()); } template constexpr bool chmin(T &a, const S b){if(a>b) return a=b,true; return false;} template constexpr bool chmax(T &a, const S b){if(a istream& operator >> (istream& i, pair &p){return i >> p.first >> p.second;} template ostream& operator << (ostream& o, const pair &p){return o << p.first << ' ' << p.second;} #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template void _do(vector x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template void _do(set x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template void _do(unordered_set x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template void _do(T && x) {cerr << x << endl;} template void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 777771449 #endif template void print(vector x){for(auto i: x) cout << i << ' ';cout << "\n";} template void print(set x){for(auto i: x) cout << i << ' ';cout << "\n";} template void print(unordered_set x){for(auto i: x) cout << i << ' ';cout << "\n";} template void print(T && x) {cout << x << "\n";} template void print(T && x, S&&... y) {cout << x << ' ';print(y...);} template istream& operator >> (istream& i, vector &vec){for(auto &x: vec) i >> x; return i;} vvi read_graph(int n, int m, int base=1){ vvi adj(n); for(int i=0,u,v; i> u >> v,u-=base,v-=base; adj[u].pb(v),adj[v].pb(u); } return adj; } vvi read_tree(int n, int base=1){return read_graph(n,n-1,base);} template pair operator + (const pair &a, const pair &b){return {a.first+b.first,a.second+b.second};} template constexpr T inf=0; template<> constexpr int inf = 0x3f3f3f3f; template<> constexpr ll inf = 0x3f3f3f3f3f3f3f3f; template vector operator += (vector &a, int val){for(auto &i: a) i+=val; return a;} template T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;} #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) //#include //using namespace atcoder; //using mint=modint998244353; //using mint=modint1000000007; // BEGIN: library/mod/montgomery_modint.hpp #line 1 "library/mod/montgomery_modint.hpp" // BEGIN: library/nt/extgcd.hpp #line 1 "library/nt/extgcd.hpp" // ax + by = gcd(a,b), {gcd(a,b),x,y} template array extgcd(T a, T b){ T x1=1,y1=0,x2=0,y2=1; while(b!=0){ T q=a/b; a%=b; swap(a,b); T x3=x1-x2*q,y3=y1-y2*q; x1=x2,y1=y2,x2=x3,y2=y3; } return {a,x1,y1}; } template T modinv(T x, T m){ auto [g,val1,val2]=extgcd(x,m); assert(g==1); if(val1<0) val1+=m; return val1; }// END: library/nt/extgcd.hpp #line 4 "library/mod/montgomery_modint.hpp" // arbitrary modint, odd mod // stores x*(2^K) mod m // https://judge.yosupo.jp/problem/binomial_coefficient_prime_mod // https://judge.yosupo.jp/problem/primality_test (used by miller rabin) template // support multiple modulos at the same time struct montgomery_modint{ using mint=montgomery_modint; inline static word m,r,val64,m2; // m = modulo < 2^(K-2), r = (-m^(-1)) (mod 2^K), val64 = (2^(2K)) (mod m), m2 = 2m static void set_mod(word _m){ assert((_m&1)&&_m<(word(1)<<(K-2))); m=_m,r=m,val64=(-dword(m))%m,m2=m*2; // use Newton's method to calculate p^(-1) (mod 2^K) // starts from p = p^(-1) (mod 4) for(int i=0; i<5; ++i) r*=2-m*r; r=-r; assert(r*m==word(-1)); } static int get_mod(){ return m; } word x; montgomery_modint():x(0){} montgomery_modint(int64_t _x):x(reduce(dword((_x%m+m)%m)*val64)){} word reduce(const dword &y) const { // (y + (yr mod 2^K)*p) / (2^K) // 0 <= return < 2p return (y+dword(word(y)*r)*m)>>K; } mint operator += (const mint &o){ x+=o.x; if(x>=m2) x-=m2; return *this; } mint operator -= (const mint &o){ x-=o.x; if(int32_t(x)<0) x+=m2; return *this; } mint operator *= (const mint &o){ x=reduce(dword(x)*o.x); return *this; } mint operator /= (const mint &o){ return (*this)*=o.inv(); } mint operator + (const mint &o) const {return mint(*this)+=o;} mint operator - (const mint &o) const {return mint(*this)-=o;} mint operator * (const mint &o) const {return mint(*this)*=o;} mint operator / (const mint &o) const {return mint(*this)/=o;} mint operator - () const {return mint(0)-*this;} mint pow(int64_t n) const { assert(n>=0); mint res=1,b=*this; for(; n; n>>=1,b*=b) if(n&1) res*=b; return res; } inline mint inv1() const { return pow(m-2); } inline mint inv2() const { auto [g,val1,val2]=extgcd(get(),m); assert(g==1); return mint(val1); } mint inv() const { if(is_prime) return inv1(); return inv2(); } bool operator == (const mint &o) const { return (x>=m?x-m:x)==(o.x>=m?o.x-m:o.x); } bool operator != (const mint &o) const { return (x>=m?x-m:x)!=(o.x>=m?o.x-m:o.x); } word get() const { word res=reduce(x); return res>=m?res-m:res; } friend istream& operator >> (istream& is, mint &b){ int64_t y; is >> y; b=mint(y); return is; } friend ostream& operator << (ostream& os, const mint &b){ return os << b.get(); } static constexpr pair ntt_data(){ return {-1,-1}; } }; template using montgomery_modint_32=montgomery_modint; template using montgomery_modint_64=montgomery_modint;// END: library/mod/montgomery_modint.hpp #line 113 "main.cpp" // BEGIN: library/mod/modint_basic.hpp #line 1 "library/mod/modint_basic.hpp" template mint fac(int n){ static const int mod=mint::get_mod(); static vector res={1,1}; if(n>=mod) return 0; assert(n>=0); while(n>=(int)res.size()) res.push_back(res.back()*res.size()); return res[n]; } template mint inv(int n){ static const int mod=mint::get_mod(); static vector res={0,1}; assert(n>=0&&n=(int)res.size()) res.push_back(res[mod%res.size()]*(mod-mod/res.size())); return res[n]; } template mint ifac(int n){ static const int mod=mint::get_mod(); static vector res={1,1}; if(n>=mod) return 0; assert(n>=0); while(n>=(int)res.size()) res.push_back(res.back()*inv(res.size())); return res[n]; } template mint C(int n, int m){ if(m<0||m>n) return 0; return fac(n)*ifac(m)*ifac(n-m); } template mint stars_and_bars(int n, int m){ if(n<0||m<0) return 0; if(n==0){ if(m==0) return 1; return 0; } return C(m+n-1,n-1); }// END: library/mod/modint_basic.hpp #line 114 "main.cpp" // BEGIN: library/poly/poly.hpp #line 1 "library/poly/poly.hpp" #line 4 "library/poly/poly.hpp" // BEGIN: library/poly/convolution.hpp #line 1 "library/poly/convolution.hpp" // BEGIN: library/poly/ntt.hpp #line 1 "library/poly/ntt.hpp" template struct NTT{ static constexpr int m=mint::get_mod(),N=mint::ntt_data().first,g=mint::ntt_data().second; mint w[N+1]; NTT(){ w[N]=g; for(int i=N-1; i>=0; --i) w[i]=w[i+1]*w[i+1]; } void trans(vector &a, int k, bool inv=false){ for(int i=1,j=0; i<(1<>=1); if(i>1); j>1); ++j,++j2,cur*=dw){ mint tmp=a[j2]*cur; a[j2]=a[j]-tmp; a[j]+=tmp; } } } if(inv){ reverse(a.begin()+1,a.end()); mint inv=mint(1< vector convolution_naive(vector a, vector b){ if(a.empty()||b.empty()) return {}; int n=((int)a.size())+((int)b.size())-1; vector res(n); for(int i=0; i<((int)a.size()); ++i) for(int j=0; j<((int)b.size()); ++j){ res[i+j]+=a[i]*b[j]; } return res; } template vector convolution_ntt(vector a, vector b){ if(a.empty()||b.empty()) return {}; static NTT ntt; int n=((int)a.size())+((int)b.size())-1; int m=1,k=0; while(m vector convolution(vector a, vector b){ if(a.empty()||b.empty()) return {}; int n=((int)a.size())+((int)b.size())-1; if(mint::ntt_data().first<0||n<49) return convolution_naive(a,b); return convolution_ntt(a,b); }// END: library/poly/convolution.hpp #line 5 "library/poly/poly.hpp" template struct poly: vector{ using vector::vector; poly(const vector &v):vector(v){} poly operator += (const poly &o){ if(o.size()>this->size()) this->resize(o.size()); for(int i=0; i<(int)o.size(); ++i) (*this)[i]+=o[i]; return *this; } poly operator += (const mint &o){ if(this->empty()) this->resize(1); (*this)[0]+=o; return *this; } poly operator -= (const poly &o){ if(o.size()>this->size()) this->resize(o.size()); for(int i=0; i<(int)o.size(); ++i) (*this)[i]-=o[i]; return *this; } poly operator -= (const mint &o){ if(this->empty()) this->resize(1); (*this)[0]-=o; return *this; } poly operator *= (const poly &o){ return *this=convolution(*this,o); } poly operator *= (const mint &o){ for(int i=0; i<(int)this->size(); ++i) (*this)[i]*=o; return *this; } poly operator + (const poly &o) const {return poly(*this)+=o;} poly operator + (const mint &o) const {return poly(*this)+=o;} poly operator - (const poly &o) const {return poly(*this)-=o;} poly operator - (const mint &o) const {return poly(*this)-=o;} poly operator * (const poly &o) const {return poly(*this)*=o;} poly operator * (const mint &o) const {return poly(*this)*=o;} poly interval(int l, int r){ assert(l<=r&&r<=(int)this->size()); poly res(this->begin()+l,this->begin()+r); return res; } poly inverse(){ int n=this->size(); assert((*this)[0]!=0); poly res(1,(*this)[0].inv()); poly b=*this; for(int m=1; msize(); poly res(n-1); for(int i=0; isize(); poly res(n+1); for(int i=0; i(i+1)); return res; } poly ln(){ // a[0] = 1 int n=this->size(); if(n==1) return poly(); poly d=derivative(); poly b=*this; b.pop_back(); poly res=d*b.inverse(); res.resize(n-1); return res.integral(); } poly exp(){ // a[0] = 0 int n=this->size(); poly q(1,1); poly b=*this; b[0]+=1; for(int m=1; msize(); poly b=*this,res={1}; for(; k; b*=b,k>>=1,b.resize(n)) if(k&1) res*=b,res.resize(n); return res; } int low(){ int n=this->size(),m=0; while(m=n) return -1; return m; } poly shift(int n){ poly res(n,0); res.insert(res.end(),this->begin(),this->end()); return res; } poly pow(ll k){ // 0^0 = 1 int n=this->size(); if(k==0){ poly res(n); return res[0]=1,res; } int m=low(); if(m){ if(m==-1||k>=n||k*m>=n) return poly(n); int lft=n-k*m; poly b=interval(m,m+lft); b=b.pow(k); b=b.shift(k*m); return b; } poly b=*this; mint base=b[0].pow(k),inv=b[0].inv(); b*=inv; b=b.ln(); if(b.empty()) b.pb(0); b*=k; b=b.exp(); b*=base; return b; } poly pow_sparse(int k, int n){ // 0^0 = 1 if(k==0){ poly res(n); return res[0]=1,res; } int t=this->size(),m=low(); if(m){ if(m==-1||k>=n||1ll*k*m>=n) return poly(n); int lft=n-k*m; poly b=interval(m,t); b=b.pow_sparse(k,lft); b=b.shift(k*m); return b; } poly res(n,0); res[0]=(*this)[0].pow(k); mint inv_a0=(*this)[0].inv(); for(int i=1; i=0) res[i]-=res[i-j]*(i-j)*(*this)[j]; } for(int j=1; j=0) res[i]+=res[i-j]*(*this)[j]*j*k; } res[i]*=inv_a0*inv(i); } return res; } friend ostream& operator << (ostream& os, const poly &P){ int n=P.size(); for(int i=0; i; void mango(){ int n; ll m; int p; cin >> n >> m >> p; if(p==2){ vi a(n); cin >> a; print(a[0]*m%2); return; } mint::set_mod(p); poly P(n+1); rep(i,1,n+1) cin >> P[i]; poly p1,p2,cur={1}; mint val=1; rep(n+1){ if(i&1) p1+=cur*val*((i/2&1)?mint(-1):mint(1)); else p2+=cur*val*((i/2&1)?mint(-1):mint(1)); cur*=P; if(sz(cur)>n+1) cur.resize(n+1); val*=m-i; if(val==0) break; val/=i+1; } p2=p2.inverse(); p1*=p2; rep(i,1,n+1) cout << p1[i] << ' '; cout << "\n"; } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); cout << fixed << setprecision(20); int t=1; //cin >> t; while(t--) mango(); } // END: main.cpp