版本比较
非常快的高精度模板
正文
增加 16 行删除 16 行
12345345678921 行未改动313233343535363738393738394041424316 行未改动6061626364646566676892 行未改动16116216316416516616516616716816917024 行未改动195196197198199199200201202203163 行未改动全部展开3673683693703713713723733743755 行未改动3813823833843853853863873883893903913923903913923933943953966 行未改动**真的很快!**
- 十进制长度在 $10^6$ 级别的大整数加法耗时约 $30\operatorname{ms}$。- 十进制长度在 $10^6$ 级别的大整数乘法耗时约 $100\operatorname{ms}$。- 十进制长度在 $5\times 10^5$ 级别的大整数除法耗时约 $600\operatorname{ms}$。- 十进制长度在 $10^6$ 级别的大整数加法耗时约 $10\operatorname{ms}$。- 十进制长度在 $10^6$ 级别的大整数乘法耗时约 $200\operatorname{ms}$。- 十进制长度在 $10^6$ 级别的大整数除法耗时约 $1.5\operatorname{s}$。
同时,本模板使用 `std::vector` 动态分配内存,避免内存浪费或内存溢出。::::success[模板(已封装类 `int_t`)]```cpp21 行未改动 * please contact [Berd__](https://www.luogu.com.cn/user/959419).**//// @brief bigint moudlestruct int_t { vector<int32_t> num; vector<int16_t> num; bool sign; static constexpr int BASE=10000; static constexpr int BASE_DIGITS=4; const long double PI=acosl(-1.0); static constexpr int BASE=1000; static constexpr int BASE_DIGITS=3; const double PI=acos(-1.0); char to_char(const int &x){// maxium 36-base return (x<10?('0'+x):('A'+x)); } void normalize(){16 行未改动 } int_t() {sign=1,num.clear(); } int_t(int64_t b){(*this)=b; } int_t(string b) {(*this).from_dec(b);} int_t(vector<int32_t> a,bool sig){ int_t(vector<int16_t> a,bool sig){ (*this).num=a; (*this).sign=sig; } bool operator==(int_t &b){92 行未改动 int_t operator-=(const int_t &b){ return (*this)=(*this)-b;} int_t operator++(){ return (*this)+=1; } int_t operator--(){ return (*this)-=1; } struct Complex { long double r=0,i=0; Complex operator=(const pair<long double,long double> &b){ double r=0,i=0; Complex operator=(const pair<double,double> &b){ r=b.first,i=b.second; return *this; } Complex operator+(const Complex &b)const{24 行未改动 if(i>rev[i]-1)continue; swap(f[i],f[rev[i]]); } for(int mid=1;mid<lim;mid<<=1){ Complex wn={cosl(PI/mid),op*sinl(PI/mid)}; Complex wn={cos(PI/mid),op*sin(PI/mid)}; for(int R=mid<<1,j=0;j<lim;j+=R){ Complex w={1,0}; for(int k=0;k<mid;k++,w=w*wn){ Complex y=f[j+k],z=w*f[j+mid+k];163 行未改动全部展开**所有运算除特殊说明外运算规则同普通十进制整数。**
**以下复杂度中的 $n$ 除特殊说明外均为高精度数十进制下的长度。**
**由于是压位高精,所有运算的复杂度都带有 $\frac{1}{4}$ 的常数,这使得运算更快。****由于是压位高精,所有运算的复杂度都带有 $\frac{1}{3}$ 到 $\frac{1}{9}$ 的常数,这使得运算更快。**
-----### 功能列表(目前支持)
5 行未改动| `=` |`a = b`| 赋值 | $\mathcal O(n)$ | || `== < > <= >=` |`a < b`| 比较大小 | $\operatorname O(n)$ | || `abs()` |`a.abs()`| 返回高精度$\newline$数的绝对值 | $\mathcal O(1)$ | || `-` |`-a`| 返回当前$\newline$数字相反数 | $\mathcal O(1)$ | || `<< >>` |`a<<b a>>b`| 返回 $a\cdot base^{b}$ $\newline$或 $\frac{a}{base^{b}}$ | $\mathcal O(n)$ | $base=10^4$,$\newline$与平常的左移/右移$\newline$结果不同,**一般不要调用** || `<< >>` |`a<<b a>>b`| 返回 $a\cdot base^{b}$ $\newline$或 $\frac{a}{base^{b}}$ | $\mathcal O(n)$ | $base=10^3$,$\newline$与平常的左移/右移$\newline$结果不同,**一般不要调用** || `+ -` |`a+b a-b`| 返回两个数$\newline$的和/差 | $\mathcal O(n)$ | 复杂度中的 $n$ 为$\newline$两个参与运算的数$\newline$长度最大值 || `+= -=` |`a+=b a-=b`| $a\leftarrow a+b$ | $\mathcal O(n)$ | ^ || `++ --` |`a++ a--`| $a\leftarrow a+1$ | $\mathcal O(1)$ | 当需要处理进位时为 $\operatorname O(n)$,但平均复杂度约等于 $\mathcal O(1)$ || `*` |`a*b`| 返回两个数$\newline$的积 | $\mathcal O(n \log n)$ | 复杂度中的 $n$ 为两个$\newline$参与运算 的数长度之和 || `/` |`a/b`| 返回两个数$\newline$的商 | $\mathcal O(n \log^2 n)$ | 复杂度中的 $n$ 为两个$\newline$参与运算的数长度之和,$\newline$常数略大 || `%` |`a%b`| 返回两个数$\newline$相除的余数 | $\mathcal O(n \log^2 n)$ | ^ || `*= /= %=` |`a%b`| 乘除/取模$\newline$并赋值 | $\mathcal O(n \log^2 n)$ | ^ || `/` |`a/b`| 返回两个数$\newline$的商 | $\mathcal O(n \log n)$ | 复杂度中的 $n$ 为两个$\newline$参与运算的数长度之和,$\newline$常数略大 || `%` |`a%b`| 返回两个数$\newline$相除的余数 | $\mathcal O(n \log n)$ | ^ || `*= /= %=` |`a%b`| 乘除/取模$\newline$并赋值 | $\mathcal O(n \log n)$ | ^ || `from_dec(string s)` |`a.from_dec()`| 十进制字符串$\newline$转高精度并赋值 | $\mathcal O(n)$ | || `to_dec()` |`a.to_dec()`| 当前高精度整数$\newline$转为十进制字符串 | $\mathcal O(n)$ | || `<< >>` |`cin>>a cout<<a`| cin/cout $\newline$输入/输出 | $\mathcal O(n)$ | |::::6 行未改动