struct bigint{
int len,a[5010];
inline void init(){memset(a,0,sizeof(a));}
}
inline bigint operator/(const bigint &x,const int &y)
{
bigint tmp;tmp.init();
tmp.len=0;
int now=0;
for(int i=x.len;i>=1;i--)
{
now=now*10+x.a[i];
tmp.a[i]=now/y;
now%=y;
if(!tmp.len && tmp.a[i])tmp.len=i;
}
return tmp;
}
inline bigint operator + (const bigint &x,const bigint &y)
{
bigint now;now.init();
now.len=max(x.len,y.len);
for(int i=1;i<=max(x.len,y.len);i++)
{
now.a[i]+=(x.a[i]+y.a[i]);
now.a[i+1]+=now.a[i]/10;
now.a[i]%=10;
}
while(now.a[now.len+1])now.len++;
return now;
}
inline bigint operator - (const bigint &x,const bigint &y)
{
bigint now=x;
for(int i=1;i<=x.len;i++)
{
now.a[i]-=y.a[i];
if(now.a[i]<0)now.a[i+1]--,now.a[i]+=10;
}
while(now.a[now.len]==0 && now.len>1)now.len--;
return now;
}
inline bigint operator * (const bigint &x,const bigint &y)
{
bigint now;now.init();
now.len=x.len+y.len-1;//至少这么多位
for(int i=1;i<=x.len;i++)
{
for(int j=1;j<=y.len;j++)
{
now.a[i+j-1]+=x.a[i]*y.a[j];
now.a[i+j]+=now.a[i+j-1]/10;
now.a[i+j-1]%=10;
}
}
while(now.a[now.len+1])now.len++;
return now;
}
inline bigint C(int x,int y)
{
if(x<y)
{
bigint tmp;tmp.init();
tmp.len=1;tmp.a[1]=0;
return tmp;
}
bigint ans,tmp;
ans.init();tmp.init();
ans.len=1;ans.a[1]=1;
for(int i=x-y+1;i<=x;i++)
{
int now=i;
tmp.len=0;
while(now)
{
tmp.a[++tmp.len]=now%10;
now/=10;
}
ans=ans*tmp;
}
for(int i=1;i<=y;i++)ans=ans/i;
return ans;
}
inline void print(bigint x)
{
if(x.len==0)
{
printf("0");
return;
}
while(x.a[x.len]==0 && x.len>1)x.len--;
for(int i=x.len;i>=1;i--)printf("%d",x.a[i]);
puts("");
}剪贴板
剪贴板 5tj8qldz
剪贴板信息
剪贴板信息
- 收录
- 更新