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 ...
随机推荐
- jingchi.ai 2017.11.25-26 Onsite面试
时间:2017.11.25 - 11.26 地点:安徽安庆 来回路费报销,住宿报销. day1: 大哥哥问了我一个实际中他们遇到的问题.有n个点,将点进行分块输出,输出各个块的均值点.具体就是100* ...
- 【刷题】BZOJ 3668 [Noi2014]起床困难综合症
Description 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm 一直坚持与起床困难综合症作斗争.通过研究相关文献,他找 ...
- BZOJ2142 礼物 【扩展Lucas】
题目 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同,在小E心中分量越重的人,收到的礼物会越多.小E从商店中购买了n件礼物, ...
- 【bzoj1483】 HNOI2009—梦幻布丁
http://www.lydsy.com/JudgeOnline/problem.php?id=1483 (题目链接) 题意 $n$个布丁摆成一行,进行$m$次操作.每次将某个颜色的布丁全部变成另一种 ...
- java多线程 -- 创建线程的第三者方式 实现Callable接口
Java 5.0 在 java.util.concurrent 提供了一个新的创建执行线程的方式:Callable 接口Callable 接口类似于 Runnable,两者都是为那些其实例可能被另一个 ...
- boost::asio::deadline_timer(理解)
并发与并行: 并发和并行从宏观上来讲都是同时处理多路请求的概念.但并发和并行又有区别,并行是指两个或者多个事件在同一时刻发生:而并发是指两个或多个事件在同一时间间隔内发生. 1.Timer.1 - 使 ...
- iis配置访问错误
最近换工作,忙着熟悉新的环境,新的框架技术(银行用的EBF),各种碰坑. 总结一下iis配置过程当中遇到的一个坑------ 按照环境搭配手册一步一步的配置,在我机器上访问一直报500的错,但是同样的 ...
- grep与正则表达式详解和实例
转载自:http://www.jb51.net/article/31207.htm grep 工具,以前介绍过. grep -[acinv] '搜索内容串' filename -a 以文本文件方式搜索 ...
- MySQL数据库应用 从入门到精通 学习笔记
以下内容是学习<MySQL数据库应用 从入门到精通>过程中总结的一些内容提要,供以后自己复现使用. 一:数据库查看所有数据库: SHOW DATABASES创建数据库: CREATE DA ...
- COGS 513 八
513. 八 http://www.cogs.pro/cogs/problem/problem.php?pid=513 ★☆ 输入文件:eight.in 输出文件:eight.out 简单 ...