您的位置:首页 > 其它

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]

  


代码:

  

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: