模板 高精度套裝

2021-08-02 04:14:22 字數 2269 閱讀 3275

絕大部分來自@代號4101的 這篇部落格

隨更新可能部分描述失效

第乙個輪子~

現支援

1. 高精度加減乘除及 mod 運算

2. 單精度除法

3. 小範圍下按位右移

4. 高精度直接輸入輸出

5. 字串 / long long 轉 高精度格式

6. 自動壓位及去字首0還有一大堆有的沒的玩意兒

2017.8.6. updata

1. 支援較小範圍下右移運算 ( 卡常 )

2. 支援單精度除法

#include // max  

#include // assert

#include // printf,sprintf

#include // strlen

#include // cin,cout

#include // string類

#include // vector類

using

namespace

std;

struct bign

}void read()

if (strlen(buf + 1) - tmp > 0)

}bign& clean()

bign(ull num = 0)

bign(string s)

bign& operator = (long

long num) while (num > 0);

return *this;

} bign& operator = (const

string& str)

return (*this).clean();

} bign operator + (const bign& b) const

return c;

} bign operator - (const bign& b) const else g = 0;

c.s.push_back(x);

} return c.clean();

} bign operator * (const bign& b) const

return c.clean();

} bign operator >> (const

int& b) const

return c.clean();

}bign operator / (const

int& b) const

return c.clean();

}bign operator / (const bign& b) const

return c.clean();

} bign operator % (const bign& b) const

return m;

} // 二分法找出滿足bx<=m的最大的x

int bsearch(const bign& b, const bign& m) const

else r = x;

} }

bign& operator += (const bign& b)

bign& operator -= (const bign& b)

bign& operator *= (const bign& b)

bign& operator /= (const bign& b)

bign& operator %= (const bign& b)

bign& operator /= (const

int& b)

bign& operator >>= (const

int& b)

bool

operator

< (const bign& b) const

bool

operator >(const bign& b) const

bool

operator

<=(const bign& b) const

bool

operator>=(const bign& b) const

bool

operator!=(const bign& b) const

bool

operator==(const bign& b) const

};

高精度模板

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型別的變數轉化為大...