HDU 6061 RXD and functions
题目链接:HDU-6061
题意:给定f(x),求f(x-A)各项系数。
思路:推导公式有如下结论:

然后用NTT解决即可。
代码:
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
const LL MAXN=;
const LL MOD=; // NTT
// O(nlogn)
// Verified!
const LL P = MOD;
const LL G = ;
const LL NUM = ; LL wn[NUM];
LL A[MAXN], B[MAXN]; LL quick_mod(LL a, LL b, LL m)
{
LL ans = ;
a %= m;
while(b)
{
if(b & )
{
ans = ans * a % m;
b--;
}
b >>= ;
a = a * a % m;
}
return ans;
} void GetWn()
{
for(LL i=; i<NUM; i++)
{
LL t = << i;
wn[i] = quick_mod(G, (P - ) / t, P);
}
} void Prepare(char A[], char B[], LL a[], LL b[], LL &len)
{
len = ;
LL len_A = strlen(A);
LL len_B = strlen(B);
while(len <= * len_A || len <= * len_B) len <<= ;
for(LL i=; i<len_A; i++)
A[len - - i] = A[len_A - - i];
for(LL i=; i<len - len_A; i++)
A[i] = '';
for(LL i=; i<len_B; i++)
B[len - - i] = B[len_B - - i];
for(LL i=; i<len - len_B; i++)
B[i] = '';
for(LL i=; i<len; i++)
a[len - - i] = A[i] - '';
for(LL i=; i<len; i++)
b[len - - i] = B[i] - '';
} void Rader(LL a[], LL len)
{
LL j = len >> ;
for(LL i=; i<len-; i++)
{
if(i < j) swap(a[i], a[j]);
LL k = len >> ;
while(j >= k)
{
j -= k;
k >>= ;
}
if(j < k) j += k;
}
} void NTT(LL a[], LL len, LL on)
{
Rader(a, len);
LL id = ;
for(LL h = ; h <= len; h <<= )
{
id++;
for(LL j = ; j < len; j += h)
{
LL w = ;
for(LL k = j; k < j + h / ; k++)
{
LL u = a[k] % P;
LL t = w * (a[k + h / ] % P) % P;
a[k] = (u + t) % P;
a[k + h / ] = ((u - t) % P + P) % P;
w = w * wn[id] % P;
}
}
}
if(on == -)
{
for(LL i = ; i < len / ; i++)
swap(a[i], a[len - i]);
LL Inv = quick_mod(len, P - , P);
for(LL i = ; i < len; i++)
a[i] = a[i] % P * Inv % P;
}
} void Conv(LL a[], LL b[], LL n)
{
NTT(a, n, );
NTT(b, n, );
for(LL i = ; i < n; i++)
a[i] = a[i] * b[i] % P;
NTT(a, n, -);
} // 快速幂
// 求x^n%mod
// Verified!
LL powMod(LL x,LL n,LL mod)
{
LL res=;
while(n>)
{
if(n&) res=res*x % mod;
x=x*x % mod;
n>>=;
}
return res;
}
// 求逆元
// a和m应该互质
// 根据欧拉定理:a的逆即a^(phi(m)-1)
LL inv(LL a,LL m)
{
return powMod(a,m-,m);
// return powMod(a,eularPhi(m)-1,m);
}
LL mi[MAXN],invsum[MAXN],fac[MAXN];
LL c[MAXN];
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
GetWn();
int n;
while(scanf("%d",&n)!=EOF)
{
n++;
for(int i=;i<n;i++) scanf("%lld",&c[i]);
int m,s=;
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int tmp;
scanf("%d",&tmp);
s=(s+tmp)%MOD;
}
int len=;
while(len<*n) len*=;
mi[]=fac[]=invsum[]=invsum[]=;
for(int i=;i<n;i++)
mi[i]=mi[i-]*(P-s)%MOD;
for(int i=;i<n;i++)
fac[i]=fac[i-]*i%MOD;
for(int i=;i<n;i++)
invsum[i]=inv(fac[i],MOD);
for(int i=;i<n;i++)
A[i]=mi[i]*invsum[i]%MOD;
for(int i=;i<n;i++)
B[i]=c[n-i-]*fac[n-i-]%MOD;
for(int i=n;i<len;i++)
A[i]=B[i]=;
Conv(A, B, len);
for(int i=;i<n;i++)
printf("%lld ",A[n-i-]*invsum[i]%MOD);
printf("\n");
}
return ;
}
HDU 6061 RXD and functions的更多相关文章
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- HDU 6061 - RXD and functions | 2017 Multi-University Training Contest 3
每次NTT都忘记初始化,真的是写一个小时,Debug两个小时- - /* HDU 6061 - RXD and functions [ NTT ] | 2017 Multi-University Tr ...
- HDU 6061 RXD and functions NTT
RXD and functions Problem Description RXD has a polynomial function f(x), f(x)=∑ni=0cixiRXD has a tr ...
- HDU 6061 RXD and functions(NTT)
题意 给定一个\(n\) 次的 \(f\) 函数,向右移动 \(m\) 次得到 \(g\) 函数,第 \(i\) 次移动长度是 \(a_i\) ,求 \(g\) 函数解析式的各项系数,对 ...
- HDU 6060 - RXD and dividing | 2017 Multi-University Training Contest 3
/* HDU 6060 - RXD and dividing [ 分析,图论 ] | 2017 Multi-University Training Contest 3 题意: 给一个 n 个节点的树, ...
- HDU 6063 - RXD and math | 2017 Multi-University Training Contest 3
比赛时候面向过题队伍数目 打表- - 看了题解发现确实是这么回事,分析能力太差.. /* HDU 6063 - RXD and math [ 数学,规律 ] | 2017 Multi-Universi ...
- HDU6061 RXD and functions【NTT】
\(RXD\ and\ functions\) Problem Description RXD has a polynomial function \(f(x)\), \(f(x)=\sum ^{n} ...
- HDU 6060 RXD and dividing(思维+计算贡献值)
http://acm.hdu.edu.cn/showproblem.php?pid=6060 题意: 给定一棵 n 个节点的树,1 为根.现要将节点 2 ~ n 划分为 k 块,使得每一块与根节点形成 ...
- 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)
题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...
随机推荐
- java实现函数指针
在Java程序员面试笔试宝典中看到的东西,感觉很有用,特开此文 函数指针一般作为函数的参数来使用,开发人员在使用是可以根据自己的需求传递自动以的函数来实现指定的功能,例如,在实现排序算法时,可以通过传 ...
- MT【133】磨刀不误砍柴工
(2018,4月学考数学填空最后一题) \(f(x)=2x^2-(x-a)|x-a|-2 \ge 0\)对任意\(x\in R\)恒成立,求\(a\)的范围______ 提示:\(f(0)=a|a|- ...
- 【刷题】洛谷 P3573 [POI2014]RAJ-Rally
题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...
- 【agc023E】Inversions(线段树,动态规划)
[agc023E]Inversions(线段树,动态规划) 题面 AT 给定\(a_i\),求所有满足\(p_i\le a_i\)的排列\(p\)的逆序对数之和. 题解 首先如何计算排列\(p\)的个 ...
- 【BZOJ1835】基站选址(线段树)
[BZOJ1835]基站选址(线段树) 题面 BZOJ 题解 考虑一个比较暴力的\(dp\) 设\(f[i][j]\)表示建了\(i\)个基站,最后一个的位置是\(j\)的最小代价 考虑如何转移\(f ...
- 解题:CQOI 2017 小Q的表格
题面 首先观察$b*f(a,a+b)=(a+b)*f(a,b)$这个东西 可以化成$\frac{f(a,a+b)}{a+b}=\frac{f(a,b)}{b}$,发现这类似辗转相除求gcd 而我们两边 ...
- c/c++基本数据类型转换
If either operand is of type long double, the other operand is converted to type long double. If the ...
- Android dumpsys命令详细使用
一.dumpsys命令介绍 1.命令说明 Dumpsys用户系统诊断,它运行在设备上,并提供系统服务状态信息 命令格式: adb shell dumpsys [system serbices] 2.系 ...
- linux命令总结之traceroute命令
通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...
- Navicat数据备份
备份:点击数据库---数据传输 目标:备份地点,数据会传送到yaozh_backup 数据传输成功