@[caojiaming](/user/775551) 学校里教除法是这么教的?
by Ruiqun2009 @ 2022-11-20 11:15:35
学校不是这样教的,可我只会这样
by caojiaming @ 2022-11-20 11:19:12
```c
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int itn;
const int mx=2e4+10;
struct bign{
int l,s[mx];
bign(){l=1, memset(s,0,sizeof(s));}
bign(const int x){*this=x;}
bign operator =(const int x){
char str[25];
sprintf(str,"%d",x);
return *this=str;
}
bign operator =(const char *num){
l=strlen(num);
memset(s,0,sizeof(s));
for(int i=1;i<=l;i++) s[i]=num[l-i]-'0';
return *this;
}
bign operator +(const bign b){
int len=l>b.l?l:b.l;
bign c;
for(int i=1;i<=len;i++) c.s[i]+=s[i]+b.s[i], c.s[i+1]+=c.s[i]/10, c.s[i]%=10;
c.l=len+1;
c.clean();
return c;
}
bign operator -(const bign b){
bign c;
for(int i=1;i<=l;i++){
if(s[i]<b.s[i]) s[i]+=10, s[i+1]--;
c.s[i]=s[i]-b.s[i];
}
c.l=l;
c.clean();
return c;
}
bign operator *(const bign b){
bign c;
for(int i=1;i<=l;i++) for(int j=1;j<=b.l;j++) c.s[i+j-1]+=s[i]*b.s[j], c.s[i+j]+=c.s[i+j-1]/10, c.s[i+j-1]%=10;
c.l=l+b.l+1;
c.clean();
return c;
}
bign operator /(const bign b){
bign c,f=0;
for(int i=l;i>=1;i--){
f=f*10, f.s[1]=s[i];
while(f>=b) f=f-b,c.s[i]++;
}
c.l=l;
c.clean();
return c;
}
bign operator %(const bign b){
bign c,f=0;
for(int i=l;i>=1;i--){
f=f*10, f.s[1]=s[i];
while(f>=b) f=f-b,c.s[i]++;
}
f.l=l;
f.clean();
return f;
}
void clean(){while(l>1&&!s[l]) l--;}
bool operator >(const bign b){
if(l!=b.l) return l>b.l;
for(int i=l;i>=1;i--) if(s[i]!=b.s[i]) return s[i]>b.s[i];
return false;
}
bool operator <(const bign b){
if(l!=b.l) return l<b.l;
for(int i=l;i>=1;i--) if(s[i]!=b.s[i]) return s[i]<b.s[i];
return false;
}
bool operator ==(const bign b){
return !(*this>b)&&!(*this<b);
}
bool operator >=(const bign b){
return !(*this<b);
}
bool operator <=(const bign b){
return !(*this>b);
}
};
istream& operator >>(istream &in, bign &b){
string str;
in>>str;
b=str.c_str();
return in;
}
ostream& operator <<(ostream &out, const bign &b){
for(int i=b.l;i>=1;i--) out<<b.s[i];
return out;
}
bign fun(int x){
bign s=1;
for(int i=1;i<=x;i++) s=s*i;
return s;
}
int main(){
bign a,b;
cin>>a>>b;
cout<<a+b<<endl;
if(a>=b) cout<<a-b;
else cout<<"-"<<b-a;
cout<<endl<<a*b<<endl<<a/b<<endl<<a%b<<endl;
return 0;
}
```
代码有一点长,不要介意
可以抄,如果有不懂的也可以私信问我
不过我推荐自己手打一遍
by wssb1919810 @ 2023-01-06 12:27:31
我代码的#10也是2.71s,#10估计没人单位ms
_**~~(逃~)~~**_
by wssb1919810 @ 2023-01-06 12:29:17