版本比较
LinkCatTree
签名
增加 1 行删除 1 行
11flijkyd | 简单,直接,哈气,爽简单,直接,哈气,爽个人介绍
增加 37 行删除 138 行
1234567891011121314158910161712181920151621182220212322232424262725282926313227333428363738394041422930313233343545464736373839404950515241424344454654555647484958595051525354555657626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916058596061626339 行未改动::::info[玩一些音游]
超爽快节奏 15 & 18:https://beta.sparebeat.com/play/0b38efc4
::::
CSh2BKSqFjZb2cQ4khBs6n6Ov4sRFaLuXC48cyOZEW3BkZ
https://www.bilibili.com/video/BV1GJ411x7h7/
https://www.zhihu.com/question/296095491/answer/2031828199886280553
## Mod int
```cpptemplate <const int mod>class mod_int {
template <const int mod> class mod_int {private:
int x; typedef mod_int <mod> Q;
typedef mod_int <mod> mint;
public:
mod_int () : x (0) { }
template <class _Tp> mod_int (_Tp _x) { template <class _Tp> mod_int (_Tp _x) { x = (_x % mod + mod) % mod; } x = (_x % mod + mod) % mod; }
~mod_int () = default;
mod_int (const mod_int &other) mod_int (const mod_int &other) : x (other.x) { } : x (other.x) { } # if __cplusplus >= 201402L mod_int (mod_int &&other) noexcept mod_int (mod_int &&other) noexcept : x (std :: exchange (other.x, 0)) { } : x (std :: exchange (other.x, 0)) { }
# else
mod_int (mod_int &&other) noexcept { const int tmp = other.x; other.x = 0; this -> x = tmp; }
mod_int (mod_int &&other) noexcept { const int tmp = other.x; other.x = 0; this -> x = tmp; } # endif mod_int &operator = (const Q &other) { return *this = Q (other); } mod_int &operator = (Q &&other) noexcept { std :: swap (x, other.x); return *this; } int val () const { return x; } template <class _Tp> explicit operator _Tp () const { return _Tp (x); }
mod_int &operator = (const mint &other) { return *this = mint (other); } friend Q operator + (const Q &a, const Q &b) { const int v = a.x + b.x; return Q (v >= mod ? v - mod : v); } Q &operator += (const Q &other) { return *this = *this + other; } Q &operator ++ () { return *this = *this + Q (1); } Q operator ++ (int) { const Q old = *this; *this = *this + Q (1); return old; }
mod_int &operator = (mint &&other) noexcept { std :: swap (x, other.x); return *this; } friend Q operator - (const Q &a, const Q &b) { const int v = a.x - b.x; return Q (v < 0 ? v + mod : v); } Q operator - () const { return Q (this -> x ? mod - this -> x : 0); } Q &operator -= (const Q &other) { return *this = *this - other; } Q &operator -- () { return *this = *this - Q (1); } Q operator -- (int) { const Q old = *this; *this = *this - Q (1); return old; }
int val () const { return x; } friend Q operator * (const Q &a, const Q &b) { const int v = (long long) a.x * b.x % mod; return Q (v); } Q &operator *= (const Q &other) { return *this = *this * other; }
explicit operator int () const { return x; template <class _Tp> friend inline Q qpow (Q base, _Tp p) { if (p <= 0) return mod_int (1); Q tmp (1); for (; p; p >>= 1, base *= base) if (p & 1) tmp *= base; return tmp; } friend inline Q inv (Q x) { return qpow (x, mod - 2); } friend Q operator / (const Q &a, const Q &b) { const Q inv_b = inv (b); return a * inv_b; } Q &operator /= (const Q& other) { return *this = *this / other; }
explicit operator long long () const { return (long long) x; }
// plus
friend mint operator + (const mint &a, const mint &b) { const int tmp = a.x + b.x; return mint (tmp >= mod ? tmp - mod : tmp); }
mint &operator += (const mint &other) { return *this = *this + other; }
mint &operator ++ () { return *this = *this + mint (1); }
mint operator ++ (int) { const mint old = *this; *this = *this + mint (1); return old; }
// minus
friend mint operator - (const mint &a, const mint &b) { const int tmp = a.x - b.x; return mint (tmp < 0 ? tmp + mod : tmp); }
mint operator - () const { const int tmp = mod - this -> x; return tmp < mod ? tmp : tmp - mod; }
mint &operator -= (const mint &other) { return *this = *this - other; }
mint &operator -- () { return *this = *this - mint (1); }
mint operator -- (int) { const mint old = *this; *this = *this - mint (1); return old; }
// multiply
friend mint operator * (const mint &a, const mint &b) { const int tmp = (long long) a.x * b.x % mod; return mint (tmp); }
mint &operator *= (const mint &other) { return *this = *this * other; }
// division
template <class _Tp> friend il mint qpow (mint base, _Tp p) { if (p <= 0) return mod_int (1); mint tmp (1); for (; p; p >>= 1) { if (p & 1) tmp *= base; base *= base; } return tmp; }
friend il mint inv (mint x) { return qpow (x, mod - 2); }
// use carefully
friend mint operator / (const mint &a, const mint &b) { const mint inv_b = inv (b); return a * inv_b; }
mint &operator /= (const mint& other) { return *this = *this / other; }
friend bool operator == (const mint &a, const mint &b) { return a.x == b.x; }
friend bool operator != (const mint &a, const mint &b) { return a.x != b.x; } friend bool operator == (const Q &a, const Q &b) { return a.x == b.x; } friend bool operator != (const Q &a, const Q &b) { return a.x != b.x; }};```
[1](https://www.zhihu.com/question/2072260638768997299/answer/2082088964106752772)39 行未改动