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 ...
随机推荐
- [BZOJ4556][Tjoi2016&Heoi2016]字符串 后缀数组+主席树
4556: [Tjoi2016&Heoi2016]字符串 Time Limit: 20 Sec Memory Limit: 128 MB Description 佳媛姐姐过生日的时候,她的小 ...
- Ubuntu实用软件安装[转]
Gedit编辑器配置 Ubuntu14.04从安装软件到卸载软件,删除安装包 linux wget 命令用法详解(附实例说明) ==================================== ...
- MQTT - Connect报文解析
#include <bits/stdc++.h> using namespace std; int main() { ] = { /* * 固定报头: MQTT报文类型(1), 保留位 * ...
- 【刷题】洛谷 P4209 学习小组
题目描述 共有n个学生,m个学习小组,每个学生只愿意参加其中的一些学习小组,且一个学生最多参加k个学习小组.每个学生参加学习小组财务处都收一定的手续费,不同的学习小组有不同的手续费.若有a个学生参加第 ...
- 【刷题】BZOJ 3529 [Sdoi2014]数表
Description 有一张n×m的数表,其第i行第j列(1<=i<=n,1<=j<=m)的数值为能同时整除i和j的所有自然数之和.给定a,计算数表中不大于a的数之和. In ...
- 使用jQuery在javascript中自定义事件
js中的自定义事件有attachEvent,addEventListener等等好多种,往往受困于浏览器兼容,而且代码写起来也相当麻烦.jQuery为我们解决了这个问题,几行代码就可以很好的实现事件的 ...
- 【转】一口气读懂NB-IoT
在过去的一年多,NB-IoT真的可以说是大红大紫.在通信圈里,除了说5G,就是说物联网.如果说物联网,八成就是在说NB-IoT. 在目前5G还没来的情况下,NB-IoT基本上是独领风骚.风光无限. 各 ...
- 洛谷 P3190 [HNOI2007]神奇游乐园 解题报告
P3190 [HNOI2007]神奇游乐园 Description 给你一个 \(m * n\) 的矩阵,每个矩阵内有个权值\(V(i,j)\) (可能为负数),要求找一条回路,使得每个点最多经过一次 ...
- 【bug】Could not find method compile() 解决
集成第三方库出现 Error:Could not find method compile() for arguments [com.android.support:design:23.4.0] on ...
- CentOS 6.6搭建LNMP环境
一.安装前 1.关闭linux的安全机制 vim /etc/selinux/config SELINUX=enforcing 改为 SELINUX=disabled 2.关闭iptables防火墙 ...