[xsy2978]Product of Roots
$\newcommand{align}[1]{\begin{align*}#1\end{align*}}$题意:给出$f(x)=\prod\limits_{i=1}^n(a_ix+1)$和$g(x)=\prod\limits_{j=1}^m(b_jx+1)$的各项系数,求$h(x)=\prod\limits_{i=1}^n\prod\limits_{j=1}^m(a_ib_jx+1)$的前$k$项系数
乘积的形式不好处理,取个$\ln$就可以化为和的形式
$\align{\ln(a_ix+1)=\int\frac{a_i}{a_ix+1}\mathrm dx=\sum\limits_{k\geq1}\dfrac{(-1)^{k+1}}ka_i^kx^k}$
$\align{\ln(b_jx+1)=\sum\limits_{k\geq1}\dfrac{(-1)^{k+1}}kb_j^kx^k}$
$\align{\ln(a_ib_jx+1)=\sum\limits_{k\geq1}\dfrac{(-1)^{k+1}}ka_i^kb_j^kx^k}$
容易发现我们把前两个式子的系数做点积,再对$\forall k\geq1$把第$k$位乘上$(-1)^{-k+1}k$就得到了第三个式子的系数
所以我们把$\ln f(x)$和$\ln g(x)$的系数如此处理后就得到了$\ln h(x)$的系数,$\exp$回去即可
#include<stdio.h> #include<string.h> typedef long long ll; const int mod=998244353,maxn=262144; void swap(int&a,int&b){a^=b^=a^=b;} int mul(int a,int b){return a*(ll)b%mod;} int ad(int a,int b){return(a+b)%mod;} int de(int a,int b){return(a-b)%mod;} int pow(int a,int b){ int s=1; while(b){ if(b&1)s=mul(s,a); a=mul(a,a); b>>=1; } return s; } int rev[maxn],N,iN; void pre(int n){ int i,k; for(N=1,k=0;N<n;N<<=1)k++; for(i=0;i<N;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1)); iN=pow(N,mod-2); } void ntt(int*a,int on){ int i,j,k,t,w,wn; for(i=0;i<N;i++){ if(i<rev[i])swap(a[i],a[rev[i]]); } for(i=2;i<=N;i<<=1){ wn=pow(3,on==1?(mod-1)/i:(mod-1-(mod-1)/i)); for(j=0;j<N;j+=i){ w=1; for(k=0;k<i>>1;k++){ t=mul(w,a[i/2+j+k]); a[i/2+j+k]=de(a[j+k],t); a[j+k]=ad(a[j+k],t); w=mul(w,wn); } } } if(on==-1){ for(i=0;i<N;i++)a[i]=mul(a[i],iN); } } int t0[maxn]; void getinv(int*a,int*b,int n){ if(n==1){ b[0]=pow(a[0],mod-2); return; } int i; getinv(a,b,n>>1); pre(n<<1); memset(t0,0,N<<2); memcpy(t0,a,n<<2); ntt(t0,1); ntt(b,1); for(i=0;i<N;i++)b[i]=mul(b[i],2-mul(b[i],t0[i])); ntt(b,-1); for(i=n;i<N;i++)b[i]=0; } int t1[maxn],inv[maxn]; void getln(int*a,int*b,int n){ int i; memset(t1,0,n<<3); getinv(a,t1,n); for(i=1;i<n;i++)b[i-1]=mul(i,a[i]); ntt(b,1); ntt(t1,1); for(i=0;i<N;i++)b[i]=mul(b[i],t1[i]); ntt(b,-1); for(i=n-1;i>0;i--)b[i]=mul(b[i-1],inv[i]); b[0]=0; for(i=n;i<N;i++)b[i]=0; } int t2[maxn]; void exp(int*a,int*b,int n){ if(n==1){ b[0]=1; return; } int i; exp(a,b,n>>1); memset(t2,0,n<<3); getln(b,t2,n); for(i=0;i<n;i++)t2[i]=de(a[i],t2[i]); t2[0]++; ntt(b,1); ntt(t2,1); for(i=0;i<N;i++)b[i]=mul(b[i],t2[i]); ntt(b,-1); for(i=n;i<N;i++)b[i]=0; } int f[maxn],g[maxn],lf[maxn],lg[maxn],lh[maxn],h[maxn]; int main(){ int N,n,m,k,i; scanf("%d%d%d",&n,&m,&k); for(i=0;i<=n;i++)scanf("%d",f+i); for(i=0;i<=m;i++)scanf("%d",g+i); for(N=1;N<n+1||N<m+1||N<k+1;N<<=1); inv[1]=1; for(i=2;i<N;i++)inv[i]=-mul(mod/i,inv[mod%i]); getln(f,lf,N); getln(g,lg,N); for(i=0;i<N;i++)lh[i]=mul(mul(lf[i],lg[i]),i&1?i:-i); exp(lh,h,N); for(i=0;i<k;i++)printf("%d ",ad(h[i],mod)); }
[xsy2978]Product of Roots的更多相关文章
- 【xsy2978】Product of Roots 生成函数+多项式ln+多项式exp
题目大意:给你两个多项式$f(x)$和$g(x)$,满足$f(x)=\prod\limits_{i=1}^{n}(a_i+1)$,$g(x)=\prod\limits_{i=1}^{m}(b_i+1) ...
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Peterhof
A. City Wall 找规律. #include<stdio.h> #include<iostream> #include<string.h> #include ...
- gc roots 垃圾回收
gc roots包括以下几个: 虚拟机栈(栈桢中的本地变量表)中的引用对象 方法区中的类静态属性引用的对象 方法区中的常量引用的对象 本地方法栈中JNI(即native方法)的引用的对象 java,c ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [LeetCode] Product of Array Except Self 除本身之外的数组之积
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...
- [LeetCode] Maximum Product Subarray 求最大子数组乘积
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- vector - vector product
the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...
- 1 Maximum Product Subarray_Leetcode
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Leetcode Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
随机推荐
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C
C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 使用HTML实现对汉字拼音的支持
<!DOCTYPE HTML><html> <head> <meta charset="utf-8"> <title>无 ...
- 解读dbcp自动重连那些事
转载自:http://agapple.iteye.com/blog/791943 可以后另一篇做对比:http://agapple.iteye.com/blog/772507 同样的内容,不同的描述方 ...
- maven项目在eclipse tomcat正常运行
转摘自:http://binary.duapp.com/2013/10/1577.html 配置下部署路径即可.
- SpringMVC学习 -- IDEA 创建 HelloWorld
SpringMVC 概述: Spring 为展现层提供的基于 MVC 实际理念的优秀 Web 框架 , 是目前最主流的 MVC 框架之一. 自 Spring3.0 发布及 2013 年 Struts ...
- maven在add dependecy时搜索不出jar包的解决办法
一:前言 其实我一直都很头疼maven的项目管理的,因为觉得用起来还是没有那么方便的啊,不过今天我自己算是小弄了下maven项目的故那里,是一个同事在配置maven的项目,我去凑了下热闹而已,现在自己 ...
- Spring - IoC(2): 属性注入 & 构造注入
依赖注入是指程序运行过程中,如果需要另外的对象协作(访问它的属性或调用它的方法)时,无须在代码中创建被调用者,而是依赖于外部容器的注入. 属性注入(Setter Injection) 属性注入是指 I ...
- NGINX : 如何屏蔽未被定义的虚拟主机的访问
参考: [ how to prevent undefined server names ] nginx 的默认虚拟主机 Nginx 支持基于域名和端口的虚拟主机(virtual host), 根据获取 ...
- [转载]超赞!32款扁平化Photoshop PSD UI工具包(下)
32款扁平化风格的UI工具包第二弹!上篇为大家分享了16款风格各异的UI Kits,下篇继续为大家呈上16款精美的UI工具包,全部都有Photoshop PSD文件可以下载哦,喜欢就赶紧收藏吧! 17 ...
- HDU 1798 Tell me the area (数学)
题目链接 Problem Description There are two circles in the plane (shown in the below picture), there ...