打印1
#define BUF_SIZE 33554432
char __buff__[BUF_SIZE];char *__p1__=__buff__,*__p2__=__buff__;
#define getChar (__p1__==__p2__&&(__p2__=(__p1__=__buff__)
+fread(__buff__,1,BUF_SIZE,stdin),__p1__==__p2__)?EOF:*__p1__++)
高精度,压位每位 \(32768\),除单精,模单精,减高精,其他运算均同时支持高精、单精
不支持负数
单精指小于 \(32768\) 的数,即使是同时支持单精、高精的运算,大于 \(32768\) 的数也需转高精运算
struct BigInt{
#define BASE 32768
#define SIZE 85
long long a[SIZE];
inline BigInt(){a[0]=1;}
inline long long operator [] (const int &pos)const{return a[pos];}
inline long long &operator [] (const int &pos){return a[pos];}
inline void clear(){__builtin_memset(a,0,sizeof a);a[0]=1;}
inline void init(){a[0]=1;}
inline void operator = (const BigInt &o){__builtin_memcpy(a,o.a,sizeof a);}
inline void operator = (long long o){
if(!o) return;
a[0]=0;
while(o) a[++a[0]]=o%BASE,o/=BASE;
}
inline long long toLL(){
long long ans=0;
for(int i=a[0];i;i--) ans=ans*BASE+a[i];
return ans;
}
inline void refresh(){
for(int i=a[0]+1;i<SIZE;i++) a[i]=0;
for(int i=1;i<=a[0];i++) a[i+1]+=a[i]/BASE,a[i]%=BASE;
while(a[a[0]+1]) a[0]++,a[a[0]+1]+=a[a[0]]/BASE,a[a[0]]%=BASE;
while(!a[a[0]]&&a[0]>1) a[0]--;
}
inline BigInt operator + (const BigInt &o){
BigInt ans;ans=*this;
for(int i=1;i<=o[0];i++) ans[i]+=o[i];lib::chkMax(ans[0],o[0]);
ans.refresh();
return ans;
}
inline void operator += (const BigInt &o){
for(int i=1;i<=o[0];i++) a[i]+=o[i];lib::chkMax(a[0],o[0]);refresh();
}
inline BigInt operator + (const long long &o){
BigInt ans;ans=*this;
ans[1]+=o;ans.refresh();
return ans;
}
inline void operator += (const long long &o){
a[1]+=o;refresh();
}
inline BigInt operator - (const BigInt &o){
BigInt ans;ans=*this;
for(int i=1;i<=o[0];i++){
ans[i]-=o[i];
if(ans[i]<0) ans[i]+=BASE,ans[i+1]--;
}
ans.refresh();
return ans;
}
inline void operator -= (const BigInt &o){
for(int i=1;i<=o[0];i++){
a[i]-=o[i];
if(a[i]<0) a[i]+=BASE,a[i+1]--;
}
refresh();
}
inline BigInt operator * (const BigInt &o){
BigInt ans;ans.clear();
for(int i=1;i<=a[0];i++)for(int j=1;j<=o[0];j++) ans[i+j-1]+=a[i]*o[j];ans[0]=a[0]+o[0]-1;
ans.refresh();
return ans;
}
inline void operator *= (const BigInt &o){
*this=*this*o;
}
inline BigInt operator * (const long long &o){
BigInt ans;ans.clear();ans[0]=a[0];
for(int i=1;i<=a[0];i++) ans[i]=a[i]*o;ans.refresh();
return ans;
}
inline void operator *= (const long long &o){
for(int i=1;i<=a[0];i++) a[i]*=o;refresh();
}
inline BigInt operator / (const long long &o){
BigInt ans,copy;ans.clear();copy=*this;
int back=a[0];
for(int i=a[0];i;i--) ans[i]=copy[i]/o,copy[i-1]+=(copy[i]%o)*BASE;
ans[0]=back;ans.refresh();
return ans;
}
inline void operator /= (const long long &o){
int back=a[0];
for(int i=a[0];i;i--) a[i-1]+=(a[i]%o)*BASE,a[i]/=o;
a[0]=back;refresh();
}
inline long long operator % (const long long &o){
return (*this-(*this/o)*o).toLL();
}
inline int operator < (const BigInt &b){
if(a[0]^b[0]) return a[0]<b[0];
for(int i=a[0];i;i--)if(a[i]^b[i]) return a[i]<b[i];
return 0;
}
inline int operator <= (const BigInt &b){
if(a[0]^b[0]) return a[0]<b[0];
for(int i=a[0];i;i--)if(a[i]^b[i]) return a[i]<b[i];
return 1;
}
inline int operator > (const BigInt &b){
if(a[0]^b[0]) return a[0]>b[0];
for(int i=a[0];i;i--)if(a[i]^b[i]) return a[i]>b[i];
return 0;
}
inline int operator >= (const BigInt &b){
if(a[0]^b[0]) return a[0]>b[0];
for(int i=a[0];i;i--)if(a[i]^b[i]) return a[i]>b[i];
return 1;
}
#undef BASE
#undef SIZE
};