没记忆化取模前T了最后一个点
记忆化后吸氧2.34s过了
#include <bits/stdc++.h>
#define re register
using namespace std;
typedef long long ll;
typedef unsigned short us;
const ll N=(ll)(3e4+10);
//¸ß¾«¶ÈÄ£°å
struct bigint{
char a[N];
short len;
bitset<1>fuhao;//0ΪÕý£¬1Ϊ¸º
//¹¹Ôì¸ß¾«¶ÈÕûÊý
bigint()
{
memset(a,0,sizeof(a));
len=0;
fuhao=0;
}
//¸ß¾«¶ÈÇåÁã
inline void clear()
{
memset(a,0,sizeof(a));
len=0;
fuhao=0;
}
/*******¸ß¾«¶È×ÔÔËËã*******/
//¸ß¾«¶È¾ø¶ÔÖµ
inline void bigabs()
{
fuhao=0;
}
//¸ß¾«¶È½øλ/ÍËλ
inline void fix()
{
while(a[len+1]) len++;
while(len>=1 && !a[len]) len--;
if(len==0) fuhao=0;
}
//¸ß¾«¶È×ÔÈ¡¸º
inline bigint operator-()
{
fuhao=~fuhao;
return *this;
}
/********¸ß¾«¶È¸³Öµ*******/
//µ¥¾«¶È¸³Öµ¸ß¾«¶È
inline bigint operator=(ll x)
{
memset(a,0,sizeof(a));
if(x<0) fuhao=1,x=-x;
else fuhao=0;
len=0;
do
{
a[++len]=x%10;
x/=10;
}while(x);
fix();
return *this;//·µ»ØÕâ¸öÊýµÄÖ¸Õë
}
//¸ß¾«¶È¸³Öµ¸ß¾«¶È
inline bigint operator=(const bigint &num)
{
memset(a,0,sizeof(a));
fuhao=num.fuhao;
len=num.len;
for(re short i=1;i<=len;i++)
a[i]=num.a[i];
fix();
return *this;
}
/******¸ß¾«¶È¼ò»¯ÔËËã*****/
//ÑϸñÒâÒå¸ß¾«¶È¼õ·¨(a>0,b>0,a>b)
inline bigint bigjian(bigint c,bigint y)
{
for(re short i=1;i<=y.len;i++)
{
if(c.a[i]<y.a[i])
{
//Ç¿ÖÆÒ»´ÎÐÔ½èÍêλ
re short j=i+1;
while(!c.a[j])
{
c.a[j]=9;
j++;
}
c.a[j]--;
c.a[i]+=10;
c.a[i]-=y.a[i];
}
else c.a[i]-=y.a[i];
}
c.fix();
return c;
}
//³ý·¨ÒâÒå¸ß¾«¶È¼õ·¨
inline void chujian(bigint &c,bigint y)
{
for(re short i=1;i<=y.len;i++)
{
if(c.a[i]<y.a[i])
{
//Ç¿ÖÆÒ»´ÎÐÔ½èÍêλ
re short j=i+1;
while(!c.a[j])
{
c.a[j]=9;
j++;
}
c.a[j]--;
c.a[i]+=10;
c.a[i]-=y.a[i];
}
else c.a[i]-=y.a[i];
}
}
//¼ò»¯Ð¡ÓÚÔËËã
inline bool xiaoyu(const bigint &b,const bigint &c)
{
if(b.len>c.len) return false;
else if(b.len<c.len) return true;
else
{
for(re short i=len;i>=1;i--)
{
if(b.a[i]==c.a[i]) continue;
if(b.a[i]<c.a[i]) return true;
else return false;
}
return false;
}
}
//ÑϸñÒâÒå¸ß¾«¶È¼õµ¥¾«¶È(a>0,b>0,a>b)
inline bigint bigjian(bigint x,ll y)
{
bigint c;c=y;
return bigjian(x,c);
}
//¸ß¾«¶ÈµÄ¸ß¾«¶ÈÃÝ(b^c)
inline bigint qmi(bigint b,bigint c)
{
bigint d,e;
d=1,e=b;
char now=c.a[1];
while(c>0)
{
if(c.a[1]&1) d=d*e;
e=e*e;
c=c/2;
}
if(now&1) d.fuhao=b.fuhao;
return d;
}
//¸ß¾«¶ÈµÄ¸ß¾«¶ÈÃÝ(b^c)%P
inline bigint qmi(bigint b,bigint c,bigint P)
{
bigint d,e;
d=1,e=b;
char now=c.a[1];
while(c>0)
{
if(c.a[1]&1) d=d*e%P;
e=e*e%P;
c=c/2;
}
if(now&1) d.fuhao=b.fuhao;
return d;
}
//¸ß¾«¶ÈµÄµ¥¾«¶ÈÃÝ
inline bigint qmi(bigint b,ll x)
{
bigint c;c=x;
return qmi(b,c);
}
//¸ß¾«¶ÈµÄµ¥¾«¶ÈÃÝ(b^c)%P
inline bigint qmi(bigint b,ll c,ll P)
{
bigint d,e;
d=c,e=P;
return qmi(b,d,e);
}
/*************¸ß¾«¶È¹Øϵ·ûºÅ************/
//¸ß¾«¶È==µ¥¾«¶È
inline bool operator==(ll x)
{
bigint c;c=x;
return (*this)==c;
}
//¸ß¾«¶È==¸ß¾«¶È
inline bool operator==(bigint c)
{
if(fuhao==c.fuhao)
{
if(len>c.len || len<c.len) return false;
else
{
for(re short i=1;i<=len;i++)
if(a[i]!=c.a[i]) return false;
return true;
}
}
else return false;
}
//¸ß¾«¶È<µ¥¾«¶È
inline bool operator<(ll x)
{
bigint c;c=x;
return (*this)<c;
}
//¸ß¾«¶È<¸ß¾«¶È
inline bool operator<(bigint c)
{
if(fuhao==c.fuhao)
{
if((*this)==c) return false;
if(fuhao==0) return xiaoyu((*this),c);
return !xiaoyu((*this),c);
}
else
{
if(fuhao==0 && c.fuhao==1) return false;
else return true;
}
}
//¸ß¾«¶È>µ¥¾«¶È
inline bool operator>(ll c)
{
return (!((*this)<=c));
}
//¸ß¾«¶È>¸ß¾«¶È
inline bool operator>(bigint c)
{
return (!((*this)<=c));
}
//¸ß¾«¶È<=µ¥¾«¶È
inline bool operator<=(ll c)
{
return ((*this)<c || (*this)==c);
}
//¸ß¾«¶È<=¸ß¾«¶È
inline bool operator<=(bigint c)
{
return ((*this)<c || (*this)==c);
}
//¸ß¾«¶È>=µ¥¾«¶È
inline bool operator>=(ll c)
{
return !((*this)<c);
}
//¸ß¾«¶È>=¸ß¾«¶È
inline bool operator>=(bigint c)
{
return !((*this)<c);
}
//¸ß¾«¶È!=¸ß¾«¶È
inline bool operator!=(bigint c)
{
return !((*this)==c);
}
//¸ß¾«¶È!=µ¥¾«¶È
inline bool operator!=(ll x)
{
return !((*this)==x);
}
/**********¸ß¾«¶È¶ÁÈëÊä³ö***********/
//¸ß¾«¶È¶ÁÈë
inline void scan()
{
memset(a,0,sizeof(a));
len=0,fuhao=0;
char c[N];
int m;
scanf("%s",c);
m=strlen(c);
for(re int i=m-1;i>=0;i--)
{
if(isdigit(c[i])) a[++len]=(c[i]^48);
else if(c[i]=='-') fuhao=1;
}
fix();
}
//¸ß¾«¶ÈÊä³ö
inline void print()
{
if(len==0) putchar('0');
else
{
if(fuhao==1) putchar('-');
for(re short i=len;i>=1;i--)
putchar(a[i]+'0');
}
}
//¸ß¾«¶Èµ÷ÊÔÊä³ö
inline void Output()
{
print();
puts("");
}
/********¸ß¾«¶ÈËÄÔòÔËËã********/
//¸ß¾«¶È+¸ß¾«¶È
inline bigint operator+(bigint b)
{
bigint c;
c.len=len+b.len;
if(fuhao==b.fuhao)
{
c.fuhao=fuhao;
//ÏȼӵÚÒ»¸öÊý
for(re short i=1;i<=len;i++)
{
c.a[i]+=a[i];
c.a[i+1]+=c.a[i]/10;
c.a[i]%=10;
}
//ÔÙ¼ÓµÚ¶þ¸öÊý
for(re short i=1;i<=b.len;i++)
{
c.a[i]+=b.a[i];
c.a[i+1]+=c.a[i]/10;
c.a[i]%=10;
}
c.fix();
return c;
}
else
{
bitset<1>tmp;
tmp=fuhao;
c=(*this);
bigint d;d=c;
b.bigabs();
d.bigabs();
if(d==b)
{
d.clear();
return d;
}
else if(d>b)
{
d=bigjian(d,b);
d.fuhao=tmp;
return d;
}
else
{
b=bigjian(b,c);
b.fuhao=~tmp;
return b;
}
}
}
//µ¥¾«¶È+¸ß¾«¶È
inline bigint operator+(ll x)
{
bigint c;c=x;
return (*this)+c;
}
//¸ß¾«¶È¼õµ¥¾«¶È
inline bigint operator-(ll c)
{
return (*this)+(-c);
}
//¸ß¾«¶È¼õ¸ß¾«¶È
inline bigint operator-(bigint c)
{
return (*this)+(-c);
}
//¸ß¾«¶È³Ë¸ß¾«¶È
inline bigint operator*(bigint b)
{
bigint c;
if(fuhao==b.fuhao) c.fuhao=0;
else c.fuhao=1;
if((*this==0) || b==0)
{
c.clear();
return c;
}
c.len=len+b.len;
//a[i]*b.a[j]=c.a[i+j-1]
for(re short i=1;i<=len;i++)
for(re short j=1;j<=b.len;j++)
{
c.a[i+j-1]+=a[i]*b.a[j];
if(c.a[i+j-1]>=10)
{
c.a[i+j]+=c.a[i+j-1]/10;
c.a[i+j-1]%=10;
}
}
c.fix();
return c;
}
//¸ß¾«¶È³Ëµ¥¾«¶È
inline bigint operator*(ll x)
{
bigint c;c=x;
return (*this)*c;
}
//¸ß¾«¶È³ýÒԸ߾«¶È
inline bigint operator/(bigint b)
{
assert(b!=0);
bigint c,d,ans;
c=(*this);d=c;
ans.len=max(d.len,b.len);
if(fuhao==b.fuhao) ans.fuhao=0;
else ans.fuhao=1;
d.bigabs();
b.bigabs();
if(d<b)
{
d.clear();
return d;
}
for(re short i=len;i>=b.len;i--)
{
while(!d.a[i]) i--;
bigint tmpa,tmpb;
tmpb=b;
for(re short j=i-b.len+1;j<=i;j++)
tmpa.a[++tmpa.len]=d.a[j];
if(tmpa<tmpb)
{
if(!(i-b.len)) continue;
tmpa.a[0]=d.a[i-b.len];
tmpa.len++;
for(re short j=tmpa.len;j>=1;j--) tmpa.a[j]=tmpa.a[j-1];
tmpa.a[0]=0;
for(re short j=1;j<=9;j++)
if((tmpb*j)<=tmpa)
ans.a[i-b.len]=j;
tmpb=tmpb*ans.a[i-b.len];
chujian(tmpa,tmpb);
for(re short j=i-1+(tmpa.a[tmpa.len]==0),k=tmpa.len;k>=1;j--,k--)
d.a[j]=tmpa.a[k];
}
else
{
for(re short j=1;j<=9;j++)
if(tmpb*j<=tmpa)
ans.a[i-b.len+1]=j;
tmpb=tmpb*ans.a[i-b.len+1];
chujian(tmpa,tmpb);
for(re short j=i,k=tmpa.len;k>=1;j--,k--)
d.a[j]=tmpa.a[k];
}
if(d.a[i]) i++;
}
ans.fix();
return ans;
}
//¸ß¾«¶È³ýÒÔµ¥¾«¶È
inline bigint operator/(ll x)
{
bigint c;c=x;
return (*this)/c;
}
//¸ß¾«¶ÈÄ£µ¥¾«¶È
inline bigint operator%(ll x)
{
bigint c;c=x;
return (*this)%c;
}
//¸ß¾«¶ÈÄ£¸ß¾«¶È
inline bigint operator%(bigint c)
{
assert(c!=0);
bigint b,d;
b=(*this);d=b;
bigint e=(d/c)*c;
return d-e;
}
};
//¶ÁÓÅ
inline ll read()
{
re ll x=0,flag=1;re char ch=getchar();
while(!isdigit(ch)) flag=(ch=='-')?-1:flag,ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*flag;
}
bigint a,b,c,d;
int main()
{
//freopen("P1932_10.in","r",stdin);
//freopen("P1932_10.out","w",stdout);
a.scan();
b.scan();
(a+b).Output();
(a-b).Output();
(a*b).Output();
c=a/b;
c.Output();
d=a-c*b;
d.Output();
return 0;
}