高精度模板

2022-02-27 12:11:03 字數 3080 閱讀 1869

我其實只是存個模板……

真的只是存個模板……

而已啦……

支援高精度加減乘除以及快速冪……但是沒有負數……(少用而且不想寫……要的話自己寫寫符號位……)

#include#include

#include

using

namespace

std;

const

int bi=1e4,mn=300

;char c[1001

];struct

big inline

void

read()

inline

void

pr()

inline big

operator =(int

x) a[

0]=0

;

while

(x)

if (!a[0]) a[0]=1

; }

inline big(

intx)

inline

void

gl()

inline

void

operator =(big x)

inline

bool

operator >(big y)

return0;

}inline

bool

operator >=(const

big y)

return1;

}inline

bool

operator

return0;

}inline

bool

operator

<=(big y)

return1;

}inline

bool

operator ==(big y)

return1;

}inline

bool

operator !=(big y)

inline

bool

operator ==(int

y) inline

bool

operator !=(int

y) inline

void swap(big &a,big &b)

inline big

operator +(big x)

return

r; }

inline big

operator +(int

x)else

break

;

return

r; }

inline big

operator -(big x)

r.gl();

return

r; }

inline big

operator -(int

x) inline big

operator *(big y)

}for (i=1;i<=r.a[0];i++)

if (r.a[i]>=bi)

return

r; }

inline big

operator *(int

y)

return

r; }

inline big half()

inline big

operator /(big y)

return

l; }

inline big

operator %(big y)

inline big

operator ^(int

y)

return

ans;

}inline big

operator ^(big y)

return

ans;

}};int

main()

view code

這是乙個int128模版,用兩個unsigned long long儲存

#define ll unsigned long longll m[

2315

];struct

mmh

void

half()

void

two()

};mmh

operator +(const mmh &x,const mmh &y)

mmh

operator +(const mmh &x,const

int &y)

mmh

operator -(const mmh &x,const mmh &y)

mmh

operator -(const mmh &x,const

int &y)

bool

operator

bool

operator >(const mmh &x,const mmh &y)

bool

operator !=(const mmh &x,const mmh &y)

bool

operator ==(const mmh &x,const mmh &y)

mmh

operator *(const mmh &x,const mmh &y)

sss+=clock();

return

mmh;

}ll s=(1ull<<32)-1

; ll a=(x.b>>32)*(y.b>>32),_b1=(x.b&s)*(y.b>>32),b=_b1+(x.b>>32)*(y.b&s),c=(x.b&s)*(y.b&s),d;

a+=(b<_b1>

; d=c+((b&s)<<32);a+=d>32

;

return

mmh(a,d);

}

view code

高精度模板

include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum bignum const int 將乙個int型別的變數轉化為大數 big...

高精度模板

include include include include include using namespace std const int maxn 1000 struct bign bign operator const char num 過載運算子 bign const char num 支援初...

高精度模板

include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum 建構函式 bignum const int 將乙個int型別的變數轉化為大...