#include<bits/stdc++.h>
using namespace std;
namespace big_number {
/*
* 高精度模板(是vector,所以无限精度)
* 支持+,-,*,/,+=,-=,/=,%,%=,pow,==,>=,<=,>,<,!=,流输入,流输出
* 请注意,没有*=,原因自己想
* 要用的时候INT xxx就行了
* 2023.9.17 qmr工作室
*/
//定义结构体
struct INT:vector<int> {
INT(int n=0){ //初始化为0
push_back(n);//加入
check();
}
INT& check(){ //处理进位
while(!empty()&&!back())pop_back();
if(empty())return *this;
for(int i =1 ;i<size();++i){
(*this)[i]+=(*this)[i-1]/10;
(*this)[i-1]%=10;
}
//处理最高位
while(back()>=10){
push_back(back()/10);
(*this)[size()-2]%=10;
}
return *this;
}
};
//输入输出
istream& operator>>(istream &is,INT &n){
string s;
is>>s;
n.clear();//函数进位
for(int i=s.size()-1;i>=0;--i)n.push_back(s[i]-'0');
return is;
}
ostream& operator<<(ostream &os,const INT &n){
if(n.empty())os<<0;
for(int i=n.size()-1;i>=0;--i)os<<n[i];
return os;
}
//比较
bool operator!=(const INT &a,const INT &b){
if(a.size()!=b.size())return 1;
for(int i=a.size()-1;i>=0;--i)
if(a[i]!=b[i])return 1;
return 0;
}
bool operator==(const INT &a,const INT &b){
return !(a!=b);
}
bool operator<(const INT &a,const INT &b){
if(a.size()!=b.size())return a.size()<b.size();
for(int i=a.size()-1;i>=0;--i)
if(a[i]!=b[i])return a[i]<b[i];
return 0;
}
bool operator>(const INT &a,const INT &b){
return b<a;
}
bool operator<=(const INT &a,const INT &b){
return !(a>b);
}
bool operator>=(const INT &a,const INT &b){
return !(a<b);
}
INT& operator+=(INT &a,const INT &b){
if(a.size()<b.size())a.resize(b.size());
for(int i=0;i!=b.size();++i)a[i]+=b[i];
return a.check();
}
INT operator+(INT a,const INT &b){
return a+=b;
}
//减法,返回差的绝对值
INT& operator-=(INT &a,INT b){
if(a<b)swap(a,b);
for(int i=0;i!=b.size();a[i]-=b[i],++i)
if(a[i]<b[i]){
int j=i+1;
while(!a[j])++j;
while(j>i){
--a[j];
a[--j]+=10;
}
}
return a.check();
}
INT operator-(INT a,const INT &b){
return a-=b;
}
INT operator*(const INT &a,const INT &b){
INT n;
n.assign(a.size()+b.size()-1,0);
for(int i=0;i!=a.size();++i)
for(int j=0;j!=b.size();++j)
n[i+j]+=a[i]*b[j];
return n.check();
}
INT& operator*=(INT &a,const INT &b){
return a=a*b;
}
//带余除法
INT divmod(INT &a,const INT &b){
INT ans;
for(int t=a.size()-b.size();a>=b;--t){
INT d;
d.assign(t+1,0);//初始化全部为 0
d.back()=1; //最后一位改成 1
INT c=b*d; //其实就是c赋予b的值
while(a>=c){
a-=c;
ans+=d;
}
}
return ans;
}
INT operator/(INT a,const INT &b){
return divmod(a,b);
}
INT& operator/=(INT &a,const INT &b){
return a=a/b;
}
INT& operator%=(INT &a,const INT &b){
divmod(a,b);
return a;
}
INT operator%(INT a,const INT &b){
return a%=b;
}
INT pow(const INT &n,const INT &k){ //快速幂
if(k.empty())return 1;
if(k==2)return n*n;
if(k.back()%2)return n*pow(n,k-1);
return pow(pow(n,k/2),2);
}
}
using namespace big_number;
int main(){
return 0;
}剪贴板
剪贴板 jng0cbgo
剪贴板信息
剪贴板信息
- 收录
- 更新