{This program computes the product of two binary numbers in multiple precision by two methods. The first method computes the FFT of each sequence, multiply the FFTs component-wise, then computes the inverse FFT, resulting in the convolution. The second computes the convolution by the naive method. In either method, the convolution is converted to the binary product by scanning from the lower positions in O(n) time. } program ex(input,output); const pai = 3.141592; type complex = record re : real; im : real end; t = array[0..100000] of complex; var i,j,m,n,c1,c2:integer; x,y,z,u,v,s,w:t; a, b,c: array[0..100000] of integer; procedure add(var z, x, y : complex); begin z.re:=x.re+y.re; z.im:=x.im+y.im end; procedure sub(var z, x, y : complex); begin z.re:=x.re-y.re; z.im:=x.im-y.im end; procedure mul(var z, x, y : complex); begin z.re:=x.re*y.re-x.im*y.im; z.im:=x.re*y.im+x.im*y.re end; procedure fft(var u:t; x:t; n:integer; sign:integer); { sign = 1 : FFT, sign = -1 : inverse FFT } var i,l,n1,k1,k,d,e,i0,i1,i2,jL,jR,kL,kR,kk,c1,c2 : integer; z0,z1 : complex; y : t; begin {c1:=clock;} for i:=0 to n-1 do w[i].re:=cos(i*2*pai/n); for i:=0 to n-1 do w[i].im:=sign*sin(i*2*pai/n); k:=1; m:=0; while k