裸FFT
#include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define ForkD(i,k,n) for(int i=n;i>=k;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1) #define Rson ((o<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define pb push_back #define mp make_pair #define eps (1e-4) #define MAXN (150000+10) #define pi ((double)3.1415926535897932384626) typedef long long ll; typedef complex<double> cd; int n; complex<double> A[MAXN],B[MAXN]; void brc(complex<double> *A,int l) { int i,j,k; for(i=1,j=l>>1;i<l-1;i++) { if (i<j) swap(A[i],A[j]); k=l>>1; while(j>=k) { j-=k; k>>=1; } j+=k; } } void pri(cd A[],int l) { Rep(i,l) printf("(%.lf,%.lf)",A[i].real(),A[i].imag()); cout<<endl; } void pri(cd A) { printf("(%.lf,%.lf)",A.real(),A.imag()); cout<<endl; } void DFT(cd *A,int l,int on) //on { brc(A,l); for(int h=2;h<=l;h<<=1) { cd wn=cd(cos(on*2*pi/h),sin(on*2*pi/h)); for(int j=0;j<l;j+=h) { cd w=cd(1,0); for(int k=j;k<j+h/2;k++) { cd u=A[k],t=w*A[k+h/2]; A[k]=u+t; A[k+h/2]=u-t; w*=wn; } } } if (on==-1) Rep(i,l) A[i].real()/=l; //DFT = 逆矩阵=-A/l } void scan(cd A[],int n) { MEM(A) RepD(i,n-1) { char c=getchar(); A[i]=cd(c-'0',0); } } cd e[MAXN]={0}; int ans[MAXN]={0}; int main() { // freopen("bzoj2179.in","r",stdin); // freopen(".out","w",stdout); scanf("%d\n",&n); scan(A,n); scanf("\n"); scan(B,n); int k=1; while(k<n) k<<=1; k<<=1; n=k; Rep(i,n) e[i]=cd(cos(2*pi*i/n),sin(2*pi*i/n)); DFT(A,n,1); DFT(B,n,1); Rep(i,n) A[i]*=B[i]; DFT(A,n,-1); Rep(i,n) { ans[i]+=A[i].real()+0.5; ans[i+1]+=ans[i]/10; ans[i]%=10; } while (n>0&&ans[n]==0) --n; RepD(i,n) printf("%d",ans[i]); return 0; }