HDU 6061 RXD and functions NTT
2017-08-02 13:07
411 查看
RXD and functions
[align=left][b]Problem Description[/b][/align]RXD has a polynomial function f(x), f(x)=∑ni=0cixi
RXD has a transformation of function Tr(f,a), it returns another function g, which has a property that g(x)=f(x−a).
Given a1,a2,a3,…,am, RXD generates a polynomial function sequence gi, in which g0=f and gi=Tr(gi−1,ai)
RXD wants you to find gm, in the form of ∑mi=0bixi
You need to output bi module 998244353.
n≤105
[align=left][b]Input[/b][/align]
There are several test cases, please keep reading until EOF.
For each test case, the first line consists of 1 integer n, which means degF.
The next line consists of n+1 intergers ci,0≤ci<998244353, which means the coefficient of the polynomial.
The next line contains an integer m, which means the length of a.
The next line contains m integers, the i - th integer is ai.
There are 11 test cases.
0<=ai<998244353
∑m≤105
[align=left][b]Output[/b][/align]
For each test case, output an polynomial with degree n, which means the answer.
[align=left][b]Sample Input[/b][/align]
2
0 0 1
1
1
[align=left][b]Sample Output[/b][/align]
1 998244351 1
Hint
$(x - 1) ^ 2 = x^2 - 2x + 1$
[b]题解:[/b]
![](https://images2017.cnblogs.com/blog/786903/201708/786903-20170802130606068-1798933912.png)
代码:
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define pii pair<int,int> #define MP make_pair typedef long long LL; typedef unsigned long long ULL; const long long INF = 1e18+1LL; const double pi = acos(-1.0); const int N = 5e5+10, M = 1e3+20,inf = 2e9; const long long P=998244353LL,mod = 998244353LL; const LL G=3LL; LL mul(LL x,LL y){ return (x*y-(LL)(x/(long double)P*y+1e-3)*P+P)%P; } LL qpow(LL x,LL k){ LL ret=1; while(k){ if(k&1) ret=mul(ret,x); k>>=1; x=mul(x,x); } return ret; } LL wn[50]; void getwn(){ for(int i=1; i<=40; ++i){ int t=1<<i; wn[i]=qpow(G,(P-1)/t); } } int len; void NTT(LL y[],int op){ for(int i=1,j=len>>1,k; i<len-1; ++i){ if(i<j) swap(y[i],y[j]); k=len>>1; while(j>=k){ j-=k; k>>=1; } if(j<k) j+=k; } int id=0; for(int h=2; h<=len; h<<=1) { ++id; for(int i=0; i<len; i+=h){ LL w=1; for(int j=i; j<i+(h>>1); ++j){ LL u=y[j],t=mul(y[j+h/2],w); y[j]=u+t; if(y[j]>=P) y[j]-=P; y[j+h/2]=u-t+P; if(y[j+h/2]>=P) y[j+h/2]-=P; w=mul(w,wn[id]); } } } if(op==-1){ for(int i=1; i<len/2; ++i) swap(y[i],y[len-i]); LL inv=qpow(len,P-2); for(int i=0; i<len; ++i) y[i]=mul(y[i],inv); } } LL c ,fac ,ans ,inv ,id ,s ,t ; int n; void solve(LL mo) { if(mo == 0) { for(int i = 0; i <= n; ++i) ans[i] = c[i]; return ; } mo = (mod - mo) % mod; len = 1; while(len <= 2*n+5) len<<=1; id[0] = 1; for(int i = 1; i <= n; ++i) id[i] = id[i-1] * mo % mod; for(int i = 0; i < len ; ++i) s[i] = 0,t[i] = 0; for(int i = 0; i <= n; ++i) s[i] = c[i]*fac[i]%mod, t[n - i] = id[i] * inv[i] % mod; NTT(s,1),NTT(t,1); for(int i = 0; i < len; ++i) s[i] = s[i]*t[i] % mod; NTT(s,-1); for(int i = 0; i <= n; ++i) { ans[i] = s[n+i]*inv[i] % mod; } } int m; int main() { getwn(); while(scanf("%d",&n)!=EOF) { for(int i = 0; i <= n; ++i) { scanf("%lld",&c[i]); } fac[0] = 1; for(int i = 1; i <= n; ++i) { fac[i] = fac[i-1]*1LL*i%mod; } inv =qpow(fac ,mod-2); for(int i = n-1; i >= 0; --i) inv[i]=inv[i+1]*1ll*(i+1)%mod; scanf("%d",&m); int sum = 0; for(int i = 1; i <= m; ++i) { int x; scanf("%d",&x); sum += x; sum %= mod; } solve(sum); for(int i = 0; i < n; ++i) printf("%lld ",ans[i]); printf("%lld \n",ans ); } return 0; }
相关文章推荐
- HDU 6061 RXD and functions(NTT)
- 解题报告:HDU_6061 RXD and functions NTT
- HDU 6061 RXD and functions(NTT+卷积)
- [HDU] 6061 RXD and functions [NTT]
- 2017 多小训练第三场 HDU 6061 RXD and functions
- 2017 多校3 hdu 6061 RXD and functions
- hdu 6061 RXD and functions [快速数论变换]
- HDU 6061 RXD and functions
- HDU 6061 RXD and functions
- 【推导】【NTT】hdu6061 RXD and functions(NTT)
- 17暑假多校联赛3.8 HDU 6063 RXD and math
- hdu--6060--RXD and dividing
- Hdu 6060 RXD and dividing【思维】
- (打表或数学)HDU 6063 RXD and math
- HDU 6063 RXD and math+(快速幂)+多校联赛第三场
- HDU 6063 RXD and math
- 【HDU 6060 RXD and dividing】+ DFS
- hdu 6060 RXD and dividing
- HDU 6063 RXD and math
- HDU 6060 RXD and dividing