my new 高精度模板【高精度】
几个小时码出来的东西。
还不错,貌似没什么bug,只不过有事会玄学水土不服(雾)(例如我校OJ上)。
几分钟就把洛谷试炼场过掉了。
只不过没有压位,有些遗憾,以后还要码一码。
换了一种代码风格,感觉好一些,但是需要习惯习惯。
2018.7.30:upd 查了一点bug
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int LEN=1005,MOD=10;
char STR[LEN];
struct bign{
int len,num[LEN];
bign(){
memset(num,0,sizeof(num));
len=1;
}
bign operator = (const char s[]){
memset(num,0,sizeof(num));
len=strlen(s);
for(int i=len;i>=1;i--){
if(s[len-i]<'0'||s[len-i]>'9'){
num[i]=s[len-i]-'A'+10;
}
else num[i]=s[len-i]-'0';
}
return *this;
}
bign operator = (int n){
memset(num,0,sizeof(num));
len=0;
do{
num[++len]=n%MOD;
n/=MOD;
}while(n);
return *this;
}
bign operator = (long long n){
memset(num,0,sizeof(num));
len=0;
do{
num[++len]=n%MOD;
n/=MOD;
}while(n);
return *this;
}
bign(const char n[]){
*this=n;
}
bign(const int n){
*this=n;
}
bign(const long long n){
*this=n;
}
bool operator < (const bign &b) const{
if(len!=b.len) return len<b.len;
for(int i=len;i>=1;i--){
if(num[i]!=b.num[i]){
return num[i]<b.num[i];
}
}
return false;
}
bool operator > (const bign &n) const{
return n<*this;
}
bool operator <= (const bign &n) const{
return !(n<*this);
}
bool operator >= (const bign &n) const{
return !(*this<n);
}
bool operator == (const bign &n) const{
return !(n<*this||*this<n);
}
bool operator != (const bign &n) const{
return n<*this||*this<n;
}
void clear(){
while(!num[len]&&len>1) len--;
}
bign operator + (const bign &b){
bign c;
c.len=max(len,b.len);
int jw=0;
for(int i=1;i<=c.len;i++){
c.num[i]=num[i]+b.num[i]+jw;
jw=c.num[i]/MOD;
c.num[i]%=MOD;
}
if(jw){
c.num[++c.len]=jw;
}
c.clear();
return c;
}
bign operator += (const bign &b){
*this=*this+b;
return *this;
}
bign operator - (const bign &b){
bign a=*this,c;
c.len=max(a.len,b.len);
for(int i=1;i<=c.len;i++){
if(a.num[i]<b.num[i]){
a.num[i]+=MOD;
a.num[i+1]--;
}
c.num[i]=a.num[i]-b.num[i];
}
c.clear();
return c;
}
bign operator -= (const bign &b){
*this=*this-b;
return *this;
}
bign operator * (const int &b){
bign c;
c.len=len;
int jw=0;
for(int i=1;i<=len;i++){
c.num[i]=num[i]*b+jw;
jw=c.num[i]/MOD;
c.num[i]%=MOD;
}
while(jw){
c.num[++c.len]=jw%MOD;
jw/=MOD;
}
c.clear();
return c;
}
bign operator *= (const int &b){
*this=*this*b;
return *this;
}
bign operator * (const bign &b){
bign c;
c.len=len+b.len-1;
for(int i=1;i<=len;i++){
for(int j=1;j<=b.len;j++){
c.num[i+j-1]+=num[i]*b.num[j];
}
}
int jw=0;
for(int i=1;i<=c.len;i++){
c.num[i]+=jw;
jw=c.num[i]/MOD;
c.num[i]%=MOD;
}
while(jw!=0){
c.num[++c.len]=jw%MOD;
jw/=MOD;
}
c.clear();
return c;
}
bign operator *= (const bign &b){
*this=*this*b;
return *this;
}
bign operator / (const int b){
bign c;
c.len=len;
int yu=0;
for(int i=len;i>=1;i--){
yu=yu*10+num[i];
c.num[i]=yu/b;
yu%=b;
}
c.clear();
return c;
}
bign operator /= (const int &b){
*this=*this/b;
return *this;
}
bign operator / (const bign &b){
bign a=*this,c,tmpb=b;
int now;
c.len=1;
while(tmpb*MOD<=a){
tmpb*=MOD;
c.len++;
}
now=c.len;
while(a>=b){
while(tmpb>a){
tmpb/=MOD;
now--;
}
a-=tmpb;
c.num[now]++;
}
c.clear();
return c;
}
bign operator /= (const bign &b){
*this=*this/b;
return *this;
}
int operator % (const int b)
{
int yu=0;
for(int i=len;i>=1;i--){
yu=(yu*10+num[i])%b;
}
return yu;
}
bign operator %= (const int &b){
*this=*this%b;
return *this;
}
bign operator % (const bign &b){
bign a=*this,tmpb=b;
while(tmpb*MOD<=a){
tmpb*=MOD;
}
while(a>=b){
while(tmpb>a){
tmpb/=MOD;
}
a-=tmpb;
}
a.clear();
return a;
}
bign operator %= (const bign &b){
*this=*this%b;
return *this;
}
bign operator ^ (int p){
bign a=1,x=*this;
while(p){
if(p&1) a=a*x;
x=x*x;
p>>=1;
}
return a;
}
bign operator ^= (const int &b){
*this=*this^b;
return *this;
}
void in(){
scanf("%s",STR);
*this=STR;
}
void out(){
for(int i=len;i>=1;i--){
if(num[i]<10){
putchar(num[i]+'0');
}
else{
putchar(num[i]+'A'-10);
}
}
}
};
bign a=1;
int main(){
for(int i=2;i<=100;i++){
a*=i;
}
a.out();
return 0;
}