fft

    const s=4;  
    type  
      cp=record x,y:real end;  
      arr=array[0..1 shl 17] of cp;  
    var  
      c:array[0..100000] of int64;  
      a,b,w,tt:arr; n,i,p:longint;   x,y:real;
      st:ansistring; wt:cp;  
 {  operator *(var a,b:cp)c:cp;begin c.x:=a.x*b.x-a.y*b.y;c.y:=a.x*b.y+a.y*b.x end;  
    operator +(var a,b:cp)c:cp;begin c.x:=a.x+b.x;c.y:=a.y+b.y end;  
    operator  -(var a,b:cp)c:cp; begin c.x:=a.x-b.x;c.y:=a.y-b.y end;  }
procedure dft(var a:arr;s,t:longint);
begin  
    if n>>t=1 then exit;  
    dft(a,s,t+1);  
    dft(a,s+1<<t,t+1);  
    for i:=0 to n>>(t+1)-1 do
    begin  
        p:=i<<(t+1)+s;  
      //  wt:=w[i<<t]*a[p+1<<t];  
      wt.x:=w[i<<t].x*a[p+1<<t].x-w[i<<t].y*a[p+1<<t].y; wt.y:=w[i<<t].x*a[p+1<<t].y+w[i<<t].y*a[p+1<<t].x;
       // tt[i]:=a[p]+wt;
       tt[i].x:=a[p].x+wt.x; tt[i].y:=a[p].y+wt.y;
        //tt[i+n>>(t+1)]:=a[p]-wt;  
        tt[i+n>>(t+1)].x:=a[p].x-wt.x; tt[i+n>>(t+1)].y:=a[p].y-wt.y;
    end;  
    for i:=0 to n>>t-1 do a[i<<t+s]:=tt[i];  
end;  
procedure get(var a:arr);var i,l,ll:longint;  
begin  
    readln(st);  
    while length(st)mod s<>0 do insert('0',st,0);  
    ll:=length(st) div s;  
    for l:=1 to ll do val(copy(st,l*s-s+1,s),a[ll-l].x);  
    while n>>1<l do n:=n+n;  
end;  
begin  

     n:=1; get(a);get(b);  
      for i:=0 to n-1 do w[i].x:=cos(pi*2*i/n);  
      for i:=0 to n-1 do w[i].y:=sin(pi*2*i/n);  
      dft(a,0,0); dft(b,0,0);  
      for i:=0 to n-1 do// a[i]:=a[i]*b[i];  
            begin x:=a[i].x*b[i].x-a[i].y*b[i].y; y:=a[i].x*b[i].y+a[i].y*b[i].x; a[i].x:=x; a[i].y:=y;end;
      for i:=0 to n-1 do w[i].y:=-w[i].y;  
      dft(a,0,0);  
      for i:=0 to n-1 do begin  
        c[i]:=c[i]+round(a[i].x/n);  
        c[i+1]:=c[i] div 10000;  
        c[i]:=c[i] mod 10000;  
      end;  
    while (c[i]=0)and(i>0) do dec(i);  
    for p:=i downto 0 do
    begin  
        str(c[p],st);  
        while (i<>p)and(length(st)<s) do st:='0'+st;  
        write(st);  
    end;  
//    readln; readln;
end.  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值