Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <algorithm>
- #include <string>
- #include <set>
- #include <map>
- #include <vector>
- #include <queue>
- #include <iostream>
- #include <iterator>
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <sstream>
- #include <fstream>
- #include <ctime>
- #include <cstring>
- #pragma comment(linker, "/STACK:16777216")
- using namespace std;
- #define pb push_back
- #define ppb pop_back
- #define pi 3.1415926535897932384626433832795028841971
- #define mp make_pair
- #define x first
- #define y second
- #define pii pair<int,int>
- #define pddd pair<double,double>
- #define INF 1000000000
- #define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
- #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
- #define all(c) (c).begin(), (c).end()
- #define SORT(c) sort(all(c))
- #define rep(i,n) FOR(i,1,(n))
- #define rept(i,n) FOR(i,0,(n)-1)
- #define L(s) (int)((s).size())
- #define C(a) memset((a),0,sizeof(a))
- #define VI vector <int>
- #define ll long long
- int a,b,c,d,i,j,n,m,k,kolt,l1,l2;
- char s1[300001],s2[300001],str[700001];
- struct pdd
- {
- double x,y;
- pdd():x(0),y(0) {}
- pdd(double _x,double _y):x(_x),y(_y) {}
- };
- inline pdd operator +(const pdd &a,const pdd &b)
- {
- return pdd(a.x+b.x,a.y+b.y);
- }
- inline pdd operator -(const pdd &a,const pdd &b)
- {
- return pdd(a.x-b.x,a.y-b.y);
- }
- inline pdd operator *(const pdd &a,const pdd &b)
- {
- return pdd(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
- }
- inline pdd operator /(const pdd &a,const double &b)
- {
- return pdd(a.x/b,a.y/b);
- }
- inline pdd conj(const pdd &a)
- {
- return pdd(a.x,-a.y);
- }
- int SN=-1;
- int rv[1<<18];
- pdd w[1<<18];
- void fft(pdd *a,int n,bool inv)
- {
- int cc=0;
- rept(i,30) if (n&1<<i) cc=i;
- if (cc!=SN)
- {
- SN=cc;
- rv[0]=0; rv[1]=1;
- rep(st,SN-1)
- {
- int k=1<<st;
- rept(i,k)
- {
- rv[i+(1<<st)]=rv[i]*2+1;
- rv[i]*=2;
- }
- }
- rept(i,1<<SN) w[i]=pdd(cos(2.0*pi*i/n),sin(2.0*pi*i/n));
- }
- rept(i,n) if (rv[i]<=i) swap(a[i],a[rv[i]]);
- for (int st=2;st<=n;st*=2)
- {
- int d=n/st,o=st/2;
- for (int i=0;i<n;i+=st)
- {
- for (int j=0;j<o;++j)
- {
- pdd u=a[i+j],v=a[i+j+o]*(inv?conj(w[j*d]):w[j*d]);
- a[i+j]=u+v;
- a[i+j+o]=u-v;
- }
- }
- }
- if (inv) rept(i,n) a[i]=a[i]/n;
- }
- pdd a1[1<<18],a2[1<<18];
- ll ans[(1<<18)+10];
- int main()
- {
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- gets(str); sscanf(str,"%d",&kolt);
- rep(hod,kolt)
- {
- gets(str);
- l1=0; l2=0; a=0;
- while (str[a]>='0' && str[a]<='9') s1[l1++]=str[a++];
- while (str[a]<'0' || str[a]>'9') ++a;
- while (str[a]>='0' && str[a]<='9') s2[l2++]=str[a++];
- s1[l1]=s2[l2]=0;
- d=max(l1,l2)/3+1;
- m=1; while (m<d) m*=2; m*=2;
- memset(a1,0,(m+1)*sizeof(pdd)); memset(a2,0,(m+1)*sizeof(pdd));
- b=0;
- for (int i=l1-1;i>=0;i-=3)
- {
- a=0;
- for (int j=i-2;j<=i;++j)
- {
- if (j<0) continue;
- a=a*10+s1[j]-'0';
- }
- a1[b++]=pdd(a,0);
- }
- c=0;
- for (int i=l2-1;i>=0;i-=3)
- {
- a=0;
- for (int j=i-2;j<=i;++j)
- {
- if (j<0) continue;
- a=a*10+s2[j]-'0';
- }
- a2[c++]=pdd(a,0);
- }
- c=max(c,b);
- n=1;
- while (n<c) n*=2;
- n*=2;
- fft(a1,n,0);
- fft(a2,n,0);
- rept(i,n) a1[i]=a1[i]*a2[i];
- fft(a1,n,1);
- ans[0]=0;
- for (int i=0;i<n;++i)
- {
- ans[i+1]=0;
- ans[i]+=(ll)(a1[i].x+0.5);
- ans[i+1]+=ans[i]/1000;
- ans[i]%=1000;
- }
- while (ans[n])
- {
- ans[n+1]=ans[n]/1000;
- ans[n]%=1000;
- ++n;
- }
- while (n>1 && ans[n-1]==0) --n;
- FORD(i,n-1,0)
- {
- if (i==n-1) printf("%d",(int)ans[i]); else
- printf("%03d",(int)ans[i]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement