#34. Polynomial multiplicationStatistics
- Describe
- Submit
- Custom Tests
This is a template problem.
Give you two polynomial, please output the polynomial after multiplication.
Input format
The first line is two integers nN and mm, representing the number of two polynomial respectively.
Second linen +1 n+1 An integer that represents the coefficients before the 0 0 to nn times of the first polynomial, respectively.
Third linem +1 m+1 An integer representing the coefficients before the 0 0 to mm of the first polynomial, respectively.
Output format
Linen +m +1 n+m+1 An integer representing the coefficients before the 0 0 to n+mn+m of the polynomial after multiplication.
Sample One input
1 21 21) 2 1
Output
1 4 5 2
Explanation
(1+2X)⋅(1+2x+ x2 ) = 1+4 x+ 5x 2+ 2x 3 (1+2x) (1+2x+x2) =1+4x+5x2+2x3.
Restrictions and conventions
0≤n,m≤5 0≤n,m≤105 to ensure that the coefficients in the input are greater than or equal to 0 "> 0 0 and less than equals 9 "> 9 9.
time limit : 1 s " >1< Span id= "mathjax-span-98" class= "Texatom" >s 1s
Space limitation :256MB MB
Download
Sample Data download
#include <cmath>#include<cstdio>#include<complex>using namespaceStd;typedef Complex<Double>E;Const DoublePi=acos (-1);Const intn=3e5+Ten;intN,m,l,r[n]; E A[n],b[n];voidFFT (E *a,intf) { for(intI=0; i<n;i++)if(i<R[i]) swap (a[i],a[r[i]); for(intI=1; i<n;i<<=1) {E wn (cos (Pi/i), F*sin (pi/i)); for(intp=i<<1, j=0; j<n;j+=p) {E W (1,0); for(intk=0; k<i;k++,w*=WN) {E x=a[j+k],y=w*a[j+k+i]; A[j+k]=x+y;a[j+k+i]=x-y; } } }}intMain () {scanf ("%d%d",&n,&m); for(intI=0, x;i<=n;i++) scanf ("%d", &x), a[i]=x; for(intI=0, x;i<=m;i++) scanf ("%d", &x), b[i]=x; for(m+=n,n=1; n<=m;n<<=1) l++; for(intI=0; i<n;i++) r[i]= (r[i>>1]>>1)| ((i&1) << (l1)); FFT (A,1); FFT (b,1); for(intI=0; i<=n;i++) a[i]*=B[i]; FFT (A,-1); for(intI=0; i<=m;i++) printf ("%d",(int) (A[i].real ()/n+0.5)); return 0;}/*It's better than knocking it out, FFT understanding, more days. Zky God Ben wrote in great detailhttp://blog.csdn.net/iamzky/article/details/22712347 */
Ur#34. Polynomial multiplication