题目链接:http://poj.org/problem?id=2389
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///神仙的FFT模板
const int maxn=505;
const double pi=acos(-1.0);
struct cp{double a,b;cp operator +(const cp &o)const {return (cp){a+o.a,b+o.b};}cp operator -(const cp &o)const {return (cp){a-o.a,b-o.b};}cp operator *(const cp &o)const {return (cp){a*o.a-b*o.b,b*o.a+a*o.b};}cp operator *(const double &o)const {return (cp){a*o,b*o};}cp operator !() const{return (cp){a,-b};}
}w[maxn];
int pos[maxn];
void fft_init(int len){int j=0;while((1<<j)<len)j++;j--;for(int i=0;i<len;i++)pos[i]=pos[i>>1]>>1|((i&1)<<j);
}
void fft(cp *x,int len,int sta){for(int i=0;i<len;i++) if(i<pos[i])swap(x[i],x[pos[i]]);w[0]=(cp){1,0};for(unsigned i=2;i<=len;i<<=1){cp g=(cp){cos(2*pi/i),sin(2*pi/i)*sta};for(int j=i>>1;j>=0;j-=2)w[j]=w[j>>1];for(int j=1;j<i>>1;j+=2)w[j]=w[j-1]*g;for(int j=0;j<len;j+=i){cp *a=x+j,*b=a+(i>>1);for(int l=0;l<i>>1;l++){cp o=b[l]*w[l];b[l]=a[l]-o;a[l]=a[l]+o;}}}if(sta==-1)for(int i=0;i<len;i++)x[i].a/=len,x[i].b/=len;
}
///1.5次DFT
cp x[maxn],y[maxn],z[maxn];
void FFT(ll *a,ll *b,int n,int m,ll *c){int len=1;while(len<(n+m)>>1)len<<=1;fft_init(len);for(int i=n/2;i<len;i++)x[i].a=x[i].b=0;for(int i=m/2;i<len;i++)y[i].a=y[i].b=0;for(int i=0;i<n;i++)(i&1?x[i>>1].b:x[i>>1].a)=a[i];for(int i=0;i<m;i++)(i&1?y[i>>1].b:y[i>>1].a)=b[i];fft(x,len,1),fft(y,len,1);for(int i=0;i<len/2;i++){int j=len-1&len-i;z[i]=x[i]*y[i]-(x[i]-!x[j])*(y[i]-!y[j])*(w[i]+(cp){1,0})*0.25;}for(int i=len/2;i<len;i++){int j=len-1&len-i;z[i]=x[i]*y[i]-(x[i]-!x[j])*(y[i]-!y[j])*((cp){1,0}-w[i^len>>1])*0.25;}fft(z,len,-1);for(int i=0;i<n+m;i++)if(i&1)c[i]=(ll)(z[i>>1].b+0.5);else c[i]=(ll)(z[i>>1].a+0.5);
}char s1[maxn],s2[maxn];
ll a1[maxn],a2[maxn],a3[maxn];
int main(){while(scanf("%s%s",s1,s2)!=EOF){int len1=strlen(s1),len2=strlen(s2);mst(a1,0),mst(a2,0),mst(a3,0);rep(i,0,len1) a1[len1-i-1]=1LL*(s1[i]-'0');rep(i,0,len2) a2[len2-i-1]=1LL*(s2[i]-'0');///FFT(a1,a2,len1+1,len2+1,a3);int len3=(len1+len2+2);for(int i=0;i<len3;i++){///注意进位a3[i+1]+=a3[i]/10;a3[i]%=10;}while(a3[len3]==0&&len3>=0) len3--;if(len3<0) puts("0");else {for(int i=len3;i>=0;i--) printf("%lld",a3[i]);puts("");}}return 0;
}