nvim/snippets/c/acm/Class_Math.code-snippets

108 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2024-01-06 10:59:58 +08:00
{
"Math_QuickPow": {
"prefix": "Math_QuickPow",
"body": [
"",
"ll quick_Pow(ll a, ll b, ll mod) {",
" // a的b次方模mod",
" ll res = 1, t = a;",
" while (b) {",
" if (b & 1) res = (res * t) % mod;",
" t = t * t % mod;",
" b >>= 1;",
" }",
" return res;",
"}",
"",
],
},
"Math_Fm": {
"prefix": "Math_Fm",
"body": [
"",
"ll quick_Pow(ll a, ll b, ll mod) {",
" // a的b次方模mod",
" ll res = 1, t = a;",
" while (b) {",
" if (b & 1) res = (res * t) % mod;",
" t = t * t % mod;",
" b >>= 1;",
" }",
" return res;",
"}",
"",
"ll Fm(ll a, ll mod) {",
" //费马小定理求逆元",
" return quick_Pow(a, mod - 2, mod);",
"}",
"",
],
},
"Math_C": {
"prefix": "Math_C",
"body": [
"",
"ll quick_Pow(ll a, ll b, ll mod) {",
" // a的b次方模mod",
" ll res = 1, t = a;",
" while (b) {",
" if (b & 1) res = (res * t) % mod;",
" t = t * t % mod;",
" b >>= 1;",
" }",
" return res;",
"}",
"",
"ll Fm(ll a, ll mod) {",
" //费马小定理求逆元",
" return quick_Pow(a, mod - 2, mod);",
"}",
"",
"ll C(ll n, ll m, ll mod) {",
" ll fz = 1, fm = 1;",
" for (ll i = n; i >= n - m + 1; i--) fz = fz * i % mod;",
" for (ll i = 1; i <= m; i++) fm = fm * i % mod;",
" return (fz * Fm(fm, mod)) % mod;",
"}",
"",
],
},
"Class_Math_Bignum": {
"prefix": "Class_Math_Bignum",
"body": [
"",
"class Math_Bignum {",
" public:",
" string Bignum;",
"",
" vll num;",
"",
" Math_Bignum(string s) {",
" Bignum = s;",
" for (auto i : s) num.push_back(i - '0');",
" }",
"",
" Math_Bignum(vll v) {",
" string s;",
" num = v;",
" for (auto i : v) s.push_back(i + '0');",
" }",
"",
" Math_Bignum(ll l) {",
" string s;",
" while (l) s.push_back(l % 10 + '0'), num.push_back(l % 10), l /= 10;",
" reverse(num.begin(), num.end());",
" reverse(s.begin(), s.end());",
" Bignum = s;",
" }",
"",
" ll get(ll l, ll r) {",
" ll res = 0;",
" for (int i = l - 1; i <= r - 1; i++) res = res * 10 + num[i];",
" return res;",
" }",
"};",
"",
],
},
}