#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define The Bignum of AK
#define FOR(i,x,y) for(int i=(x);i<=(y);i++)
#define DOR(i,x,y) for(int i=(x);i>=(y);i--)
char str[1005];
struct Bignum{
static const int P=10000,M=1005;
int num[M],len;
Bignum(){memset(num,0,sizeof(num));len=1;}//左闭右开,len仅表示长度
void Read(){
scanf("%s",str);
len=0;
int sz=strlen(str);
for(int i=sz-1;i>=0;i-=4){
num[len]=0;
for(int j=max(0,i-3);j<=i;j++){
num[len]=(num[len]<<3)+(num[len]<<1)+(str[j]^48);
}
len++;
}
while(len>1&&!num[len-1])len--;
}
void print(){
printf("%d",num[len-1]);
DOR(i,len-2,0)printf("%04d",num[i]);
puts("");
}
bool operator <(const Bignum &p)const{
if(len!=p.len)return len<p.len;
for(int i=len-1;i>=0;i--)if(num[i]!=p.num[i])return num[i]<p.num[i];
return false;
}
bool operator >(const Bignum &p)const{return p<*this;}
bool operator <=(const Bignum &p)const{return !(p<*this);}
bool operator ==(const Bignum &p)const{return !(p<*this||*this<p);}
bool operator !=(const Bignum &p)const{return p<*this||*this<p;}
Bignum operator +(const int &p)const{
Bignum B;B=*this;
B.num[0]+=p;
int step=0;
while(B.num[step]>=P){
B.num[step]-=P;
B.num[step+1]++;
step++;
}
while(B.num[len])B.len++;
return B;
}
Bignum operator +(const Bignum &A)const{
Bignum B;
B.len=max(len,A.len);
FOR(i,0,B.len-1){
B.num[i]+=A.num[i]+num[i];
if(B.num[i]>=P){
B.num[i]-=P;
B.num[i+1]++;
}
}
while(B.num[B.len])B.len++;
return B;
}
Bignum operator -(const int &p)const{//保证非负
Bignum B;B=*this;
B.num[0]-=p;
int step=0;
while(B.num[step]<0){
B.num[step]+=P;
B.num[step+1]--;
step++;
}
while(B.len>1&&!B.num[B.len-1])B.len--;
return B;
}
Bignum operator -(const Bignum &A)const{
Bignum B;
B.len=max(len,A.len);
FOR(i,0,B.len-1){
B.num[i]+=num[i]-A.num[i];
if(B.num[i]<0){
B.num[i]+=P;
B.num[i+1]--;
}
}
while(B.len>1&&!B.num[B.len-1])B.len--;
return B;
}
Bignum operator *(const int &p)const{
Bignum B;
B.len=len;
FOR(i,0,len-1){
B.num[i]+=num[i]*p;
if(B.num[i]>=P){
B.num[i+1]+=B.num[i]/P;
B.num[i]%=P;
}
}
while(B.num[B.len])B.len++;
return B;
}
Bignum operator *(const Bignum &A)const{
Bignum B;
B.len=len+A.len-1;
FOR(i,0,len-1){
FOR(j,0,A.len-1){
B.num[i+j]+=num[i]*A.num[j];
if(B.num[i+j]>=P){
B.num[i+j+1]+=B.num[i+j]/P;
B.num[i+j]%=P;
}
}
}
while(B.num[B.len])B.len++;
return B;
}
Bignum operator /(const int &p)const{
Bignum B;B=*this;
DOR(i,B.len-1,0){
if(i)B.num[i-1]+=B.num[i]%p*P;
B.num[i]/=p;
}
while(B.len>1&&!B.num[B.len-1])B.len--;
return B;
}
Bignum operator /(const Bignum &A)const{
Bignum l,r,res;
if(*this<A)return res;
r=*this;
while(l<=r){
Bignum mid=(l+r)/2;
if((mid*A)<=*this){
res=mid;
l=mid+1;
}
else r=mid-1;
}
return res;
}
};
int main(){
Bignum A,B;
A.Read();
B.Read();
Bignum C=A/B;
C.print();
return 0;
}
高精模板
最新推荐文章于 2020-09-03 20:40:34 发布