FFT (Fast Fourier transform): HDU 1402 A * B problem Plus

Source: Internet
Author: User

Calculate A * B.
Input each line would contain the integers A and B. Process to end of file.

Note:the length of each integer would not exceed 50000.
Output for each case, output A * B in one line.
Sample Input
1210002
Sample Output
22000
  
Alas, the template problem, the membrane of the Bingbin template.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 8 Const DoublePI = ACOs (-1.0);9 Ten structcomplex{ One     Doubler,i; AComplexDoubler_=0.0,Doublei_=0.0) -     { -R=r_;i=I_; the     } -Complexoperator+(ConstComplex &b) -     { -         returnComplex (r+b.r,i+B.I); +     } -Complexoperator-(ConstComplex &b) +     { A         returnComplex (r-b.r,i-B.I); at     } -Complexoperator*(ConstComplex &b) -     { -         returnComplex (r*b.r-i*b.i,i*b.r+r*B.I); -     } - }; in   - voidRader (Complex *a,intlen) to { +     intK; -      for(intI=1, j=len/2; i<len-1; i++) the     { *         if(i<j) Swap (A[i],a[j]); $k=len/2;Panax Notoginseng          while(j>=k) -         { thej-=K; +k>>=1; A         } thej+=K; +     } - } $  $ voidFFT (Complex *a,intLenintOn ) - { - rader (a,len); the      for(intH=2; h<=len;h<<=1) -     {WuyiComplex WN (cos (-on*2*pi/h), sin (-on*2*pi/h)); the          for(intj=0; j<len;j+=h) -         { WuComplex W (1,0); -              for(intk=j;k<j+h/2; k++) About             { $Complex u=A[k]; -Complex v=a[k+h/2]*W; -a[k]=u+v; -a[k+h/2]=u-v; Aw=w*WN; +             } the         }  -     } $     if(on==-1) the          for(intI=0; i<len;i++) theA[i].r/=Len; the } the  - Const intMAXN =200010; in complex ARRAY1[MAXN],ARRAY2[MAXN]; the CharSTR1[MAXN],STR2[MAXN]; the intSum[maxn],len,len1,len2; About  the intMain () the { the      while(~SCANF ("%s%s", STR1,STR2)) +     { -len1=strlen (str1); theLen2=strlen (STR2); Bayilen=1; the          while(len<len1*2|| len<len2*2) len<<=1; the          for(intI=0; i<len1;i++) -Array1[i]=complex (str1[len1-i-1]-'0',0); -          for(intI=0; i<len2;i++) theArray2[i]=complex (str2[len2-i-1]-'0',0); the          the          for(inti=len1;i<len;i++) theArray1[i]=complex (0,0); -          for(inti=len2;i<len;i++) theArray2[i]=complex (0,0); the          theFFT (Array1,len,1);94FFT (Array2,len,1); the          for(intI=0; i<len;i++) thearray1[i]=array1[i]*Array2[i]; theFFT (array1,len,-1);98memset (SUM,0,sizeof(sum));  About          for(intI=0; i<len;i++){ -sum[i]+= (int) (array1[i].r+0.5);101sum[i+1]+=sum[i]/Ten;102sum[i]%=Ten;103         }104         intp=Len; the          while(!sum[p]&&p) p--;106          for(;p!=-1;p--)107printf"%d", Sum[p]);108printf"\ n"); 109     } the     return 0;111}

FFT (Fast Fourier transform): HDU 1402 A * B problem Plus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.