#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
struct Big
{
static const int BASE=100000000;
static const int WIDTH=8;
long long s[10000],len;
Big()
{
memset(s,0,sizeof(s));len=0;
}
void read()
{
char str[5005];
scanf("%s",str);
int w=1;
for(int i=strlen(str)-1;i>=0;i--)
{
s[len]+=w*(str[i]-'0');
w*=10;
if(w==BASE){w=1;if(i!=0)len++;}
}
}
Big operator +(int b)
{
Big x=*this;
x.s[0]+=b;
for(int i=0;i<=x.len;i++)
{
x.s[i+1]+=x.s[i]/BASE;
x.s[i]%=BASE;
}
if(x.s[x.len+1])x.len++;
return x;
}
Big operator + (const Big &b)
{
Big x;
for(int i=0;i<=len||i<=b.len;i++)
{
if(i<=b.len)x.s[i]+=b.s[i];
if(i<=len)x.s[i]+=s[i];
x.s[i+1]+=x.s[i]/BASE;
x.s[i]%=BASE;
}
x.len=max(len,b.len);
if(x.s[x.len+1])x.len++;
return x;
}
Big operator - (const Big &b)
{
Big x;
for(int i=0;i<=len;i++)
{
while(s[i]<b.s[i])
{
s[i]+=BASE;s[i+1]--;
}
x.s[i]=s[i]-b.s[i];
}
x.len=len;
while(x.s[x.len]==0&&x.len)x.len--;
return x;
}
Big operator *(int b)
{
Big x;
for(int i=0;i<=len;i++)
{
x.s[i]+=s[i]*b;
x.s[i+1]+=x.s[i]/BASE;
x.s[i]%=BASE;
}
x.len=len;
if(x.s[x.len+1])x.len++;
return x;
}
Big operator *(const Big &b)
{
Big x;
for(int i=0;i<=len;i++)
for(int j=0;j<=b.len;j++)
{
x.s[i+j]+=s[i]*b.s[j];
x.s[i+j+1]+=x.s[i+j]/BASE;
x.s[i+j]%=BASE;
}
x.len=len+b.len;
if(x.s[len+b.len+1])x.len++;
return x;
}
Big operator / (int b)
{
Big x;
for(int i=len;i>0;i--)
{
x.s[i]=s[i]/b;
s[i-1]+=(s[i]%b)*BASE;
}
x.s[0]=s[0]/b;
x.len=len;
while(x.s[x.len]==0&&x.len)x.len--;
return x;
}
Big operator /(const Big &c)
{
Big x,f,b=c;
for(int i=len;i>=0;i--)
{
f=f+s[i];
if(f>=b)
{
int l=0,r=BASE;
while(l<r)
{
int mid=(l+r+1)>>1;
if(f>=(b*mid))l=mid;
else r=mid-1;
}
x.s[i]=l;f=f-(b*l);
}
f=f*BASE;
}
x.len=len-b.len+1;
while(x.s[x.len]==0&&x.len)x.len--;
return x;
}
bool operator <(const Big &b)
{
if(len<b.len)return true;
if(len>b.len)return false;
for(int i=len;i>=0;i--)
{
if(s[i]<b.s[i])return true;
if(s[i]>b.s[i])return false;
}
return false;
}
bool operator >=(const Big &b){
if (*this < b) return 0; return 1;
}
void print()
{
printf("%d",s[len]);
for(int i=len-1;i>=0;i--)
printf("%08d",s[i]);
}
};
int main()
{
Big a,b;
a.read();b.read();
(a+b).print();
}
[模板] 高精
最新推荐文章于 2022-10-29 11:03:52 发布