#include
#define maxlen 450//陣列長度上限,可以根據需求自行設定
#define base_digit 9//運算的進製,9代表以10^9計算
#define base 1000000000//10^9進製
#define printchar (" d")//專長整數輸出定義的字串
#define isdigit(c) (('0'<=(c))&&((c)<='9'))//判斷字元c是否為數字
using namespace std;
char instr[maxlen*base_digit+1];
short cmp(const int *a,const int *b)
return 0;
}void add(const int *a,const int *b,int *c)
}while(c[0]>1&&c[c[0]]==0)//消去前導零
c[0]--;
}void sub(const int *a,const int *b,int *c)
}while(c[0]>1&&c[c[0]]==0)
c[0]--;//消去前導零
return ;
}void mul(const int *a,const int *b,int *c)
while(c[0]>1&&c[c[0]]==0)
c[0]--;//消去前導零
}void mul(const int *a,int b,int *c)
while(c[l]==0&&l>1) l--;
c[0]=l;
}void div(const int *a,const int *b,int *c,int *d)
for(int i=l;i>0;i--)
tdmax = tdmin+1.0;
max =(int)(tdmax/tbmin)+1;min =(int)(tdmin/tbmax)-1;
while(true)
//試商偏高,改變max值
sub(d,t1,t2);
if(cmp(t2,b)>=0)//試商偏低,改變min值
break;//試商成功,此mid值為該位的商值
}c[i]=mid;
memcpy(d,t2,sizeof(int)*maxlen);//t2為餘值,賦給d
}delete t1;delete t2;
while(c[l]==0&&l>1) l--;
c[0]=l;//消去前導零
}class harint
~harint(){}
bool parse(const char *s)//為負數,數值從第2位開始
for(int j=l-1;j>=i;j-=base_digit)
//含非數字字元,賦值失敗
n+=(s[j-k]-'0')*ten;ten*=10;
}numb[nl++]=n;//從第一位開始給陣列numb賦值,第0位預留為數字長
}nl--;while(numb[nl]==0&&nl>1)nl--;//消去前導零
numb[0]=nl;return true;//賦值成功
}void clear()
void parse(const harint hi)
void value(const int a)
numb[0]=1;numb[1]=t;
}int operator(int i)
bool flag()
bool iszero()
int get()
void print(char s)
friend short harintcmp(harint,harint);//友元比較函式
friend void div(harint,harint,harint&,harint&);//友元除法函式
harint& operator+=(const harint& a)//|a|==|b|&&a*b<0則a-b=0;
else if(c<0)//|a|<|b|
else sub(n,a.numb,numb);
}delete n;n=null;
return *this;
}harint& operator-=(const harint& a)//0
else if(c<0)//aelse sub(n,a.numb,numb);//a>b符號不變
}delete n;n=null;
return *this;
}harint& operator*=(const harint& a)
harint& operator/=(const harint& a)
harint& operator%=(const harint& a)
};void div(harint a,harint b,harint& c,harint& d)
short harintcmp(harint a,harint b)
return 0;
}bool operator<(harint a,harint b)
bool operator>(harint a,harint b)
bool operator==(harint a,harint b)
bool operator!=(harint a,harint b)
bool operator<=(harint a,harint b)
bool operator>=(harint a,harint b)
harint operator+(const harint& a,const harint& b)
harint operator+(const harint& a,const int b)
harint operator-(const harint& a,const harint& b)
harint operator-(const harint& a,const int b)
harint operator*(const harint& a,const harint& b)
harint operator*(const harint& a,const int b)
harint operator/(const harint& a,const harint& b)
harint operator/(const harint& a,const int b)
harint operator%(const harint& a,const harint& b)
harint operator%(const harint& a,const int b)
高精度 模板 高精度整數加 減 乘 除模板
加減 乘除高精度加減乘除模板,可能會在求方案數 求組合數等情況下遇到,c 整形範圍 整型數範圍 int8 128 127 uint8 0 256 int16 32768 32767 uint16 0 65535 int32 2147483648 2147483647 uint32 0 4294967...
模板 高精度整數(新)
老版本 kuangbin 那個浪費空間還慢。把每一位改成極限的9位就是最快的。壓位高精在60000位整數的時候比python乘法慢了一倍。看來還是需要fft的。struct bigint bigint int v while v bigint const char s bigint operator...
大數 高精度數 模板 分享
複製 如下 include include include include include include include include include include include include include include include include include include ...