summaryrefslogtreecommitdiff
path: root/content/math
diff options
context:
space:
mode:
Diffstat (limited to 'content/math')
-rw-r--r--content/math/berlekampMassey.cpp2
-rw-r--r--content/math/bigint.cpp67
-rw-r--r--content/math/binomial0.cpp2
-rw-r--r--content/math/binomial1.cpp2
-rw-r--r--content/math/discreteLogarithm.cpp4
-rw-r--r--content/math/divisors.cpp2
-rw-r--r--content/math/gauss.cpp4
-rw-r--r--content/math/gcd-lcm.cpp4
-rw-r--r--content/math/inversions.cpp2
-rw-r--r--content/math/inversionsMerge.cpp14
-rw-r--r--content/math/lgsFp.cpp2
-rw-r--r--content/math/linearRecurrence.cpp8
-rw-r--r--content/math/linearRecurrenceOld.cpp8
-rw-r--r--content/math/linearSieve.cpp12
-rw-r--r--content/math/longestIncreasingSubsequence.cpp4
-rw-r--r--content/math/math.tex32
-rw-r--r--content/math/matrixPower.cpp8
-rw-r--r--content/math/permIndex.cpp4
-rw-r--r--content/math/piLegendre.cpp46
-rw-r--r--content/math/polynomial.cpp6
-rw-r--r--content/math/primeSieve.cpp2
-rw-r--r--content/math/recover.cpp2
-rw-r--r--content/math/rho.cpp4
-rw-r--r--content/math/shortModInv.cpp2
-rw-r--r--content/math/simpson.cpp2
-rw-r--r--content/math/sqrtModCipolla.cpp2
-rw-r--r--content/math/tables/composite.tex26
-rw-r--r--content/math/tables/prime-composite.tex31
-rw-r--r--content/math/transforms/andTransform.cpp4
-rw-r--r--content/math/transforms/bitwiseTransforms.cpp6
-rw-r--r--content/math/transforms/fft.cpp2
-rw-r--r--content/math/transforms/fftMul.cpp6
-rw-r--r--content/math/transforms/multiplyBitwise.cpp2
-rw-r--r--content/math/transforms/multiplyFFT.cpp4
-rw-r--r--content/math/transforms/multiplyNTT.cpp2
-rw-r--r--content/math/transforms/ntt.cpp2
-rw-r--r--content/math/transforms/orTransform.cpp4
-rw-r--r--content/math/transforms/seriesOperations.cpp8
-rw-r--r--content/math/transforms/xorTransform.cpp2
39 files changed, 177 insertions, 169 deletions
diff --git a/content/math/berlekampMassey.cpp b/content/math/berlekampMassey.cpp
index 29e084f..85a1031 100644
--- a/content/math/berlekampMassey.cpp
+++ b/content/math/berlekampMassey.cpp
@@ -1,6 +1,6 @@
constexpr ll mod = 1'000'000'007;
vector<ll> BerlekampMassey(const vector<ll>& s) {
- int n = sz(s), L = 0, m = 0;
+ int n = ssize(s), L = 0, m = 0;
vector<ll> C(n), B(n), T;
C[0] = B[0] = 1;
diff --git a/content/math/bigint.cpp b/content/math/bigint.cpp
index 1b3b953..a40f515 100644
--- a/content/math/bigint.cpp
+++ b/content/math/bigint.cpp
@@ -7,9 +7,9 @@ struct bigint {
bigint() : sign(1) {}
- bigint(ll v) {*this = v;}
+ bigint(ll v) { *this = v; }
- bigint(const string &s) {read(s);}
+ bigint(const string &s) { read(s); }
void operator=(ll v) {
sign = 1;
@@ -22,10 +22,11 @@ struct bigint {
bigint operator+(const bigint& v) const {
if (sign == v.sign) {
bigint res = v;
- for (ll i = 0, carry = 0; i < max(sz(a), sz(v.a)) || carry; ++i) {
- if (i == sz(res.a))
+ for (ll i = 0, carry = 0;
+ i < max(ssize(a), ssize(v.a)) || carry; ++i) {
+ if (i == ssize(res.a))
res.a.push_back(0);
- res.a[i] += carry + (i < sz(a) ? a[i] : 0);
+ res.a[i] += carry + (i < ssize(a) ? a[i] : 0);
carry = res.a[i] >= base;
if (carry)
res.a[i] -= base;
@@ -39,8 +40,8 @@ struct bigint {
if (sign == v.sign) {
if (abs() >= v.abs()) {
bigint res = *this;
- for (ll i = 0, carry = 0; i < sz(v.a) || carry; ++i) {
- res.a[i] -= carry + (i < sz(v.a) ? v.a[i] : 0);
+ for (ll i = 0, carry = 0; i < ssize(v.a) || carry; ++i) {
+ res.a[i] -= carry + (i < ssize(v.a) ? v.a[i] : 0);
carry = res.a[i] < 0;
if (carry) res.a[i] += base;
}
@@ -54,8 +55,8 @@ struct bigint {
void operator*=(ll v) {
if (v < 0) sign = -sign, v = -v;
- for (ll i = 0, carry = 0; i < sz(a) || carry; ++i) {
- if (i == sz(a)) a.push_back(0);
+ for (ll i = 0, carry = 0; i < ssize(a) || carry; ++i) {
+ if (i == ssize(a)) a.push_back(0);
ll cur = a[i] * v + carry;
carry = cur / base;
a[i] = cur % base;
@@ -74,12 +75,12 @@ struct bigint {
bigint a = a1.abs() * norm;
bigint b = b1.abs() * norm;
bigint q, r;
- q.a.resize(sz(a.a));
- for (ll i = sz(a.a) - 1; i >= 0; i--) {
+ q.a.resize(ssize(a.a));
+ for (ll i = ssize(a.a) - 1; i >= 0; i--) {
r *= base;
r += a.a[i];
- ll s1 = sz(r.a) <= sz(b.a) ? 0 : r.a[sz(b.a)];
- ll s2 = sz(r.a) <= sz(b.a) - 1 ? 0 : r.a[sz(b.a) - 1];
+ ll s1 = ssize(r.a) <= ssize(b.a) ? 0 : r.a[ssize(b.a)];
+ ll s2 = ssize(r.a) <= ssize(b.a) - 1 ? 0 : r.a[ssize(b.a) - 1];
ll d = (base * s1 + s2) / b.a.back();
r -= b * d;
while (r < 0) r += b, --d;
@@ -102,7 +103,7 @@ struct bigint {
void operator/=(ll v) {
if (v < 0) sign = -sign, v = -v;
- for (ll i = sz(a) - 1, rem = 0; i >= 0; --i) {
+ for (ll i = ssize(a) - 1, rem = 0; i >= 0; --i) {
ll cur = a[i] + rem * base;
a[i] = cur / v;
rem = cur % v;
@@ -119,7 +120,7 @@ struct bigint {
ll operator%(ll v) const {
if (v < 0) v = -v;
ll m = 0;
- for (ll i = sz(a) - 1; i >= 0; --i)
+ for (ll i = ssize(a) - 1; i >= 0; --i)
m = (a[i] + m * base) % v;
return m * sign;
}
@@ -139,9 +140,9 @@ struct bigint {
bool operator<(const bigint& v) const {
if (sign != v.sign) return sign < v.sign;
- if (sz(a) != sz(v.a))
- return sz(a) * sign < sz(v.a) * v.sign;
- for (ll i = sz(a) - 1; i >= 0; i--)
+ if (ssize(a) != ssize(v.a))
+ return ssize(a) * sign < ssize(v.a) * v.sign;
+ for (ll i = ssize(a) - 1; i >= 0; i--)
if (a[i] != v.a[i])
return a[i] * sign < v.a[i] * sign;
return false;
@@ -169,7 +170,7 @@ struct bigint {
}
bool isZero() const {
- return a.empty() || (sz(a) == 1 && a[0] == 0);
+ return a.empty() || (ssize(a) == 1 && a[0] == 0);
}
bigint operator-() const {
@@ -186,7 +187,7 @@ struct bigint {
ll longValue() const {
ll res = 0;
- for (ll i = sz(a) - 1; i >= 0; i--)
+ for (ll i = ssize(a) - 1; i >= 0; i--)
res = res * base + a[i];
return res * sign;
}
@@ -195,11 +196,11 @@ struct bigint {
sign = 1;
a.clear();
ll pos = 0;
- while (pos < sz(s) && (s[pos] == '-' || s[pos] == '+')) {
+ while (pos < ssize(s) && (s[pos] == '-' || s[pos] == '+')) {
if (s[pos] == '-') sign = -sign;
++pos;
}
- for (ll i = sz(s) - 1; i >= pos; i -= base_digits) {
+ for (ll i = ssize(s) - 1; i >= pos; i -= base_digits) {
ll x = 0;
for (ll j = max(pos, i - base_digits + 1); j <= i; j++)
x = x * 10 + s[j] - '0';
@@ -218,13 +219,13 @@ struct bigint {
friend ostream& operator<<(ostream& stream, const bigint& v) {
if (v.sign == -1) stream << '-';
stream << (v.a.empty() ? 0 : v.a.back());
- for (ll i = sz(v.a) - 2; i >= 0; --i)
+ for (ll i = ssize(v.a) - 2; i >= 0; --i)
stream << setw(base_digits) << setfill('0') << v.a[i];
return stream;
}
static vll karatsubaMultiply(const vll& a, const vll& b) {
- ll n = sz(a);
+ ll n = ssize(a);
vll res(n + n);
if (n <= 32) {
for (ll i = 0; i < n; i++)
@@ -242,25 +243,25 @@ struct bigint {
for (ll i = 0; i < k; i++) a2[i] += a1[i];
for (ll i = 0; i < k; i++) b2[i] += b1[i];
vll r = karatsubaMultiply(a2, b2);
- for (ll i = 0; i < sz(a1b1); i++) r[i] -= a1b1[i];
- for (ll i = 0; i < sz(a2b2); i++) r[i] -= a2b2[i];
- for (ll i = 0; i < sz(r); i++) res[i + k] += r[i];
- for (ll i = 0; i < sz(a1b1); i++) res[i] += a1b1[i];
- for (ll i = 0; i < sz(a2b2); i++) res[i + n] += a2b2[i];
+ for (ll i = 0; i < ssize(a1b1); i++) r[i] -= a1b1[i];
+ for (ll i = 0; i < ssize(a2b2); i++) r[i] -= a2b2[i];
+ for (ll i = 0; i < ssize(r); i++) res[i + k] += r[i];
+ for (ll i = 0; i < ssize(a1b1); i++) res[i] += a1b1[i];
+ for (ll i = 0; i < ssize(a2b2); i++) res[i + n] += a2b2[i];
return res;
}
bigint operator*(const bigint& v) const {
vll ta(a.begin(), a.end());
vll va(v.a.begin(), v.a.end());
- while (sz(ta) < sz(va)) ta.push_back(0);
- while (sz(va) < sz(ta)) va.push_back(0);
- while (sz(ta) & (sz(ta) - 1))
+ while (ssize(ta) < ssize(va)) ta.push_back(0);
+ while (ssize(va) < ssize(ta)) va.push_back(0);
+ while (ssize(ta) & (ssize(ta) - 1))
ta.push_back(0), va.push_back(0);
vll ra = karatsubaMultiply(ta, va);
bigint res;
res.sign = sign * v.sign;
- for (ll i = 0, carry = 0; i < sz(ra); i++) {
+ for (ll i = 0, carry = 0; i < ssize(ra); i++) {
ll cur = ra[i] + carry;
res.a.push_back(cur % base);
carry = cur / base;
diff --git a/content/math/binomial0.cpp b/content/math/binomial0.cpp
index 5f2ccaa..f37aea5 100644
--- a/content/math/binomial0.cpp
+++ b/content/math/binomial0.cpp
@@ -10,5 +10,5 @@ void precalc() {
ll calc_binom(ll n, ll k) {
if (n < 0 || n < k || k < 0) return 0;
- return (inv[k] * inv[n-k] % mod) * fac[n] % mod;
+ return (fac[n] * inv[n-k] % mod) * inv[k] % mod;
}
diff --git a/content/math/binomial1.cpp b/content/math/binomial1.cpp
index dab20b3..d0fce18 100644
--- a/content/math/binomial1.cpp
+++ b/content/math/binomial1.cpp
@@ -1,7 +1,7 @@
ll calc_binom(ll n, ll k) {
if (k > n) return 0;
ll r = 1;
- for (ll d = 1; d <= k; d++) {// Reihenfolge => Teilbarkeit
+ for (ll d = 1; d <= k; d++) { // Reihenfolge => Teilbarkeit
r *= n--, r /= d;
}
return r;
diff --git a/content/math/discreteLogarithm.cpp b/content/math/discreteLogarithm.cpp
index 68866e0..844bd27 100644
--- a/content/math/discreteLogarithm.cpp
+++ b/content/math/discreteLogarithm.cpp
@@ -5,11 +5,11 @@ ll dlog(ll a, ll b, ll m) { //a > 0!
vals[i] = {e, i};
}
vals.emplace_back(m, 0);
- sort(all(vals));
+ ranges::sort(vals);
ll fact = powMod(a, m - bound - 1, m);
for (ll i = 0; i < m; i += bound, b = (b * fact) % m) {
- auto it = lower_bound(all(vals), pair<ll, ll>{b, 0});
+ auto it = ranges::lower_bound(vals, pair<ll, ll>{b, 0});
if (it->first == b) {
return (i + it->second) % m;
}}
diff --git a/content/math/divisors.cpp b/content/math/divisors.cpp
index 5afd4fb..2a17f54 100644
--- a/content/math/divisors.cpp
+++ b/content/math/divisors.cpp
@@ -2,7 +2,7 @@ ll countDivisors(ll n) {
ll res = 1;
for (ll i = 2; i * i * i <= n; i++) {
ll c = 0;
- while (n % i == 0) {n /= i; c++;}
+ while (n % i == 0) { n /= i; c++; }
res *= c + 1;
}
if (isPrime(n)) res *= 2;
diff --git a/content/math/gauss.cpp b/content/math/gauss.cpp
index d431e52..719f573 100644
--- a/content/math/gauss.cpp
+++ b/content/math/gauss.cpp
@@ -7,7 +7,7 @@ void takeAll(int n, int line) {
for (int i = 0; i < n; i++) {
if (i == line) continue;
double diff = mat[i][line];
- for (int j = 0; j < sz(mat[i]); j++) {
+ for (int j = 0; j < ssize(mat[i]); j++) {
mat[i][j] -= diff * mat[line][j];
}}}
@@ -22,7 +22,7 @@ int gauss(int n) {
if (abs(mat[i][i]) > EPS) {
normalLine(i);
takeAll(n, i);
- done[i] = true;
+ done[i] = true;
}}
for (int i = 0; i < n; i++) { // gauss fertig, prüfe Lösung
bool allZero = true;
diff --git a/content/math/gcd-lcm.cpp b/content/math/gcd-lcm.cpp
index a1c63c8..1ee7ef5 100644
--- a/content/math/gcd-lcm.cpp
+++ b/content/math/gcd-lcm.cpp
@@ -1,2 +1,2 @@
-ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
-ll lcm(ll a, ll b) {return a * (b / gcd(a, b));}
+ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
+ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
diff --git a/content/math/inversions.cpp b/content/math/inversions.cpp
index 9e47f9b..289161f 100644
--- a/content/math/inversions.cpp
+++ b/content/math/inversions.cpp
@@ -1,7 +1,7 @@
ll inversions(const vector<ll>& v) {
Tree<pair<ll, ll>> t; //ordered statistics tree @\sourceref{datastructures/pbds.cpp}@
ll res = 0;
- for (ll i = 0; i < sz(v); i++) {
+ for (ll i = 0; i < ssize(v); i++) {
res += i - t.order_of_key({v[i], i});
t.insert({v[i], i});
}
diff --git a/content/math/inversionsMerge.cpp b/content/math/inversionsMerge.cpp
index 8235b11..50fe37b 100644
--- a/content/math/inversionsMerge.cpp
+++ b/content/math/inversionsMerge.cpp
@@ -2,26 +2,26 @@
ll merge(vector<ll>& v, vector<ll>& left, vector<ll>& right) {
int a = 0, b = 0, i = 0;
ll inv = 0;
- while (a < sz(left) && b < sz(right)) {
+ while (a < ssize(left) && b < ssize(right)) {
if (left[a] < right[b]) v[i++] = left[a++];
else {
- inv += sz(left) - a;
+ inv += ssize(left) - a;
v[i++] = right[b++];
}
}
- while (a < sz(left)) v[i++] = left[a++];
- while (b < sz(right)) v[i++] = right[b++];
+ while (a < ssize(left)) v[i++] = left[a++];
+ while (b < ssize(right)) v[i++] = right[b++];
return inv;
}
ll mergeSort(vector<ll> &v) { // Sortiert v und gibt Inversionszahl zurück.
- int n = sz(v);
+ int n = ssize(v);
vector<ll> left(n / 2), right((n + 1) / 2);
for (int i = 0; i < n / 2; i++) left[i] = v[i];
for (int i = n / 2; i < n; i++) right[i - n / 2] = v[i];
ll result = 0;
- if (sz(left) > 1) result += mergeSort(left);
- if (sz(right) > 1) result += mergeSort(right);
+ if (ssize(left) > 1) result += mergeSort(left);
+ if (ssize(right) > 1) result += mergeSort(right);
return result + merge(v, left, right);
}
diff --git a/content/math/lgsFp.cpp b/content/math/lgsFp.cpp
index bf18c86..64e4c09 100644
--- a/content/math/lgsFp.cpp
+++ b/content/math/lgsFp.cpp
@@ -7,7 +7,7 @@ void takeAll(int n, int line, ll p) {
for (int i = 0; i < n; i++) {
if (i == line) continue;
ll diff = mat[i][line];
- for (int j = 0; j < sz(mat[i]); j++) {
+ for (int j = 0; j < ssize(mat[i]); j++) {
mat[i][j] -= (diff * mat[line][j]) % p;
mat[i][j] = (mat[i][j] + p) % p;
}}}
diff --git a/content/math/linearRecurrence.cpp b/content/math/linearRecurrence.cpp
index a8adacd..eb04566 100644
--- a/content/math/linearRecurrence.cpp
+++ b/content/math/linearRecurrence.cpp
@@ -1,9 +1,9 @@
constexpr ll mod = 998244353;
// oder ntt mul @\sourceref{math/transforms/ntt.cpp}@
vector<ll> mul(const vector<ll>& a, const vector<ll>& b) {
- vector<ll> c(sz(a) + sz(b) - 1);
- for (int i = 0; i < sz(a); i++) {
- for (int j = 0; j < sz(b); j++) {
+ vector<ll> c(ssize(a) + ssize(b) - 1);
+ for (int i = 0; i < ssize(a); i++) {
+ for (int j = 0; j < ssize(b); j++) {
c[i+j] += a[i]*b[j] % mod;
}}
for (ll& x : c) x %= mod;
@@ -11,7 +11,7 @@ vector<ll> mul(const vector<ll>& a, const vector<ll>& b) {
}
ll kthTerm(const vector<ll>& f, const vector<ll>& c, ll k) {
- int n = sz(c);
+ int n = ssize(c);
vector<ll> q(n + 1, 1);
for (int i = 0; i < n; i++) q[i + 1] = (mod - c[i]) % mod;
vector<ll> p = mul(f, q);
diff --git a/content/math/linearRecurrenceOld.cpp b/content/math/linearRecurrenceOld.cpp
index 2501e64..f67398d 100644
--- a/content/math/linearRecurrenceOld.cpp
+++ b/content/math/linearRecurrenceOld.cpp
@@ -1,7 +1,7 @@
constexpr ll mod = 1'000'000'007;
vector<ll> modMul(const vector<ll>& a, const vector<ll>& b,
const vector<ll>& c) {
- ll n = sz(c);
+ ll n = ssize(c);
vector<ll> res(n * 2 + 1);
for (int i = 0; i <= n; i++) { //a*b
for (int j = 0; j <= n; j++) {
@@ -18,8 +18,8 @@ vector<ll> modMul(const vector<ll>& a, const vector<ll>& b,
}
ll kthTerm(const vector<ll>& f, const vector<ll>& c, ll k) {
- assert(sz(f) == sz(c));
- vector<ll> tmp(sz(c) + 1), a(sz(c) + 1);
+ assert(ssize(f) == ssize(c));
+ vector<ll> tmp(ssize(c) + 1), a(ssize(c) + 1);
tmp[0] = a[1] = 1; //tmp = (x^k) % c
for (k++; k > 0; k /= 2) {
@@ -28,6 +28,6 @@ ll kthTerm(const vector<ll>& f, const vector<ll>& c, ll k) {
}
ll res = 0;
- for (int i = 0; i < sz(c); i++) res += (tmp[i+1] * f[i]) % mod;
+ for (int i = 0; i < ssize(c); i++) res += (tmp[i+1] * f[i]) % mod;
return res % mod;
}
diff --git a/content/math/linearSieve.cpp b/content/math/linearSieve.cpp
index 64440dd..2ea1e94 100644
--- a/content/math/linearSieve.cpp
+++ b/content/math/linearSieve.cpp
@@ -3,12 +3,12 @@ ll small[N], power[N], sieved[N];
vector<ll> primes;
//wird aufgerufen mit (p^k, p, k) für prime p und k > 0
-ll mu(ll pk, ll p, ll k) {return -(k == 1);}
-ll phi(ll pk, ll p, ll k) {return pk - pk / p;}
-ll div(ll pk, ll p, ll k) {return k+1;}
-ll divSum(ll pk, ll p, ll k) {return (pk*p-1) / (p - 1);}
-ll square(ll pk, ll p, ll k) {return k % 2 ? pk / p : pk;}
-ll squareFree(ll pk, ll p, ll k) {return p;}
+ll mu(ll pk, ll p, ll k) { return -(k == 1); }
+ll phi(ll pk, ll p, ll k) { return pk - pk / p; }
+ll div(ll pk, ll p, ll k) { return k+1; }
+ll divSum(ll pk, ll p, ll k) { return (pk*p-1) / (p - 1); }
+ll square(ll pk, ll p, ll k) { return k % 2 ? pk / p : pk; }
+ll squareFree(ll pk, ll p, ll k) { return p; }
void sieve() { // O(N)
small[1] = power[1] = sieved[1] = 1;
diff --git a/content/math/longestIncreasingSubsequence.cpp b/content/math/longestIncreasingSubsequence.cpp
index fcb63b4..e4863d0 100644
--- a/content/math/longestIncreasingSubsequence.cpp
+++ b/content/math/longestIncreasingSubsequence.cpp
@@ -1,8 +1,8 @@
vector<int> lis(vector<ll>& a) {
- int n = sz(a), len = 0;
+ int n = ssize(a), len = 0;
vector<ll> dp(n, INF), dp_id(n), prev(n);
for (int i = 0; i < n; i++) {
- int pos = lower_bound(all(dp), a[i]) - dp.begin();
+ int pos = ranges::lower_bound(dp, a[i]) - begin(dp);
dp[pos] = a[i];
dp_id[pos] = i;
prev[i] = pos ? dp_id[pos - 1] : -1;
diff --git a/content/math/math.tex b/content/math/math.tex
index 4ac6c9e..fdf7081 100644
--- a/content/math/math.tex
+++ b/content/math/math.tex
@@ -26,7 +26,7 @@
\end{methods}
\sourcecode{math/permIndex.cpp}
\end{algorithm}
-\clearpage
+\columnbreak
\subsection{Mod-Exponent und Multiplikation über $\boldsymbol{\mathbb{F}_p}$}
%\vspace{-1.25em}
@@ -100,8 +100,8 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
wenn $a\equiv~b \bmod \ggT(m, n)$.
In diesem Fall sind keine Faktoren
auf der linken Seite erlaubt.
- \end{itemize}
- \sourcecode{math/chineseRemainder.cpp}
+ \end{itemize}
+ \sourcecode{math/chineseRemainder.cpp}
\end{algorithm}
\begin{algorithm}{Primzahltest \& Faktorisierung}
@@ -121,7 +121,7 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
\begin{algorithm}{Matrix-Exponent}
\begin{methods}
\method{precalc}{berechnet $m^{2^b}$ vor}{\log(b)\*n^3}
- \method{calc}{berechnet $m^b\cdot$}{\log(b)\cdot n^2}
+ \method{calc}{berechnet $m^b \cdot v$}{\log(b)\cdot n^2}
\end{methods}
\textbf{Tipp:} wenn \code{v[x]=1} und \code{0} sonst, dann ist \code{res[y]} = $m^b_{y,x}$.
\sourcecode{math/matrixPower.cpp}
@@ -236,7 +236,7 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
\sourcecode{math/legendre.cpp}
\end{algorithm}
-\begin{algorithm}{Lineares Sieb und Multiplikative Funktionen}
+\begin{algorithm}{Lineares Sieb und multiplikative Funktionen}
Eine (zahlentheoretische) Funktion $f$ heißt multiplikativ wenn $f(1)=1$ und $f(a\cdot b)=f(a)\cdot f(b)$, falls $\ggT(a,b)=1$.
$\Rightarrow$ Es ist ausreichend $f(p^k)$ für alle primen $p$ und alle $k$ zu kennen.
@@ -250,7 +250,7 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
\textbf{Wichtig:} Sieb rechts ist schneller für \code{isPrime} oder \code{primes}!
\sourcecode{math/linearSieve.cpp}
- \textbf{\textsc{Möbius}-Funktion:}
+ \textbf{\textsc{Möbius} Funktion:}
\begin{itemize}
\item $\mu(n)=+1$, falls $n$ quadratfrei ist und gerade viele Primteiler hat
\item $\mu(n)=-1$, falls $n$ quadratfrei ist und ungerade viele Primteiler hat
@@ -263,7 +263,7 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
\item $p$ prim, $k \in \mathbb{N}$:
$~\varphi(p^k) = p^k - p^{k - 1}$
- \item \textbf{Euler's Theorem:}
+ \item \textbf{\textsc{Euler}'s Theorem:}
Für $b \geq \varphi(c)$ gilt: $a^b \equiv a^{b \bmod \varphi(c) + \varphi(c)} \pmod{c}$. Darüber hinaus gilt: $\gcd(a, c) = 1 \Leftrightarrow a^b \equiv a^{b \bmod \varphi(c)} \pmod{c}$.
Falls $m$ prim ist, liefert das den \textbf{kleinen Satz von \textsc{Fermat}}:
$a^{m} \equiv a \pmod{m}$
@@ -321,6 +321,7 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
\end{algorithm}
\begin{algorithm}{Polynome, FFT, NTT \& andere Transformationen}
+ \label{fft}
Multipliziert Polynome $A$ und $B$.
\begin{itemize}
\item $\deg(A \cdot B) = \deg(A) + \deg(B)$
@@ -328,14 +329,15 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
$\deg(A \cdot B) + 1$ haben.
Größe muss eine Zweierpotenz sein.
\item Für ganzzahlige Koeffizienten: \code{(ll)round(real(a[i]))}
- \item \emph{xor}, \emph{or} und \emph{and} Transform funktioniert auch mit \code{double} oder modulo einer Primzahl $p$ falls $p \geq 2^{\texttt{bits}}$
+ \item \emph{or} Transform berechnet sum over subsets
+ $\rightarrow$ inverse für inclusion/exclusion
\end{itemize}
%\sourcecode{math/fft.cpp}
%\sourcecode{math/ntt.cpp}
\sourcecode{math/transforms/fft.cpp}
\sourcecode{math/transforms/ntt.cpp}
\sourcecode{math/transforms/bitwiseTransforms.cpp}
- Multiplikation mit 2 transforms statt 3: (nur benutzten wenn nötig!)
+ Multiplikation mit 2 Transforms statt 3: (nur benutzen wenn nötig!)
\sourcecode{math/transforms/fftMul.cpp}
\end{algorithm}
@@ -345,7 +347,7 @@ sich alle Lösungen von $x^2-ny^2=c$ berechnen durch:
\subsection{Kombinatorik}
-\paragraph{Wilsons Theorem}
+\paragraph{\textsc{Wilson}'s Theorem}
A number $n$ is prime if and only if
$(n-1)!\equiv -1\bmod{n}$.\\
($n$ is prime if and only if $(m-1)!\cdot(n-m)!\equiv(-1)^m\bmod{n}$ for all $m$ in $\{1,\dots,n\}$)
@@ -357,14 +359,14 @@ $(n-1)!\equiv -1\bmod{n}$.\\
\end{cases}
\end{align*}
-\paragraph{\textsc{Zeckendorfs} Theorem}
+\paragraph{\textsc{Zeckendorf}'s Theorem}
Jede positive natürliche Zahl kann eindeutig als Summe einer oder mehrerer
verschiedener \textsc{Fibonacci}-Zahlen geschrieben werden, sodass keine zwei
aufeinanderfolgenden \textsc{Fibonacci}-Zahlen in der Summe vorkommen.\\
\emph{Lösung:} Greedy, nimm immer die größte \textsc{Fibonacci}-Zahl, die noch
hineinpasst.
-\paragraph{\textsc{Lucas}-Theorem}
+\paragraph{\textsc{Lucas}'s Theorem}
Ist $p$ prim, $m=\sum_{i=0}^km_ip^i$, $n=\sum_{i=0}^kn_ip^i$ ($p$-adische Darstellung),
so gilt
\vspace{-0.75\baselineskip}
@@ -542,10 +544,10 @@ Wenn man $k$ Spiele in den Zuständen $X_1, \ldots, X_k$ hat, dann ist die \text
\input{math/tables/series}
\subsection{Wichtige Zahlen}
-\input{math/tables/composite}
+\input{math/tables/prime-composite}
-\subsection{Recover $\boldsymbol{x}$ and $\boldsymbol{y}$ from $\boldsymbol{y}$ from $\boldsymbol{x\*y^{-1}}$ }
-\method{recover}{findet $x$ und $y$ für $x=x\*y^{-1}\bmod m$}{\log(m)}
+\subsection{Recover $\boldsymbol{x}$ and $\boldsymbol{y}$ from $\boldsymbol{x\*y^{-1}}$ }
+\method{recover}{findet $x$ und $y$ für $c=x\*y^{-1}\bmod m$}{\log(m)}
\textbf{WICHTIG:} $x$ und $y$ müssen kleiner als $\sqrt{\nicefrac{m}{2}}$ sein!
\sourcecode{math/recover.cpp}
diff --git a/content/math/matrixPower.cpp b/content/math/matrixPower.cpp
index d981e6e..d80dac6 100644
--- a/content/math/matrixPower.cpp
+++ b/content/math/matrixPower.cpp
@@ -1,14 +1,14 @@
vector<mat> pows;
void precalc(mat m) {
- pows = {mat(sz(m.m), 1), m};
- for (int i = 1; i < 60; i++) pows.push_back(pows[i] * pows[i]);
+ pows = {m};
+ for (int i = 0; i < 60; i++) pows.push_back(pows[i] * pows[i]);
}
auto calc(ll b, vector<ll> v) {
- for (ll i = 1; b > 0; i++) {
+ for (ll i = 0; b > 0; i++) {
if (b & 1) v = pows[i] * v;
- b /= 2;
+ b >>= 1;
}
return v;
}
diff --git a/content/math/permIndex.cpp b/content/math/permIndex.cpp
index 4cffc12..563b33a 100644
--- a/content/math/permIndex.cpp
+++ b/content/math/permIndex.cpp
@@ -1,12 +1,12 @@
ll permIndex(vector<ll> v) {
Tree<ll> t;
- reverse(all(v));
+ ranges::reverse(v);
for (ll& x : v) {
t.insert(x);
x = t.order_of_key(x);
}
ll res = 0;
- for (int i = sz(v); i > 0; i--) {
+ for (int i = ssize(v); i > 0; i--) {
res = res * i + v[i - 1];
}
return res;
diff --git a/content/math/piLegendre.cpp b/content/math/piLegendre.cpp
index 21b974b..6401a4f 100644
--- a/content/math/piLegendre.cpp
+++ b/content/math/piLegendre.cpp
@@ -1,23 +1,23 @@
-constexpr ll cache = 500; // requires O(cache^3)
-vector<vector<ll>> memo(cache * cache, vector<ll>(cache));
-
-ll pi(ll n);
-
-ll phi(ll n, ll k) {
- if (n <= 1 || k < 0) return 0;
- if (n <= primes[k]) return n - 1;
- if (n < N && primes[k] * primes[k] > n) return n - pi(n) + k;
- bool ok = n < cache * cache;
- if (ok && memo[n][k] > 0) return memo[n][k];
- ll res = n/primes[k] - phi(n/primes[k], k - 1) + phi(n, k - 1);
- if (ok) memo[n][k] = res;
- return res;
-}
-
-ll pi(ll n) {
- if (n < N) { // implement this as O(1) lookup for speedup!
- return distance(primes.begin(), upper_bound(all(primes), n));
- } else {
- ll k = pi(sqrtl(n) + 1);
- return n - phi(n, k) + k;
-}}
+constexpr ll cache = 500; // requires O(cache^3)
+vector<vector<ll>> memo(cache * cache, vector<ll>(cache));
+
+ll pi(ll n);
+
+ll phi(ll n, ll k) {
+ if (n <= 1 || k < 0) return 0;
+ if (n <= primes[k]) return n - 1;
+ if (n < N && primes[k] * primes[k] > n) return n - pi(n) + k;
+ bool ok = n < cache * cache;
+ if (ok && memo[n][k] > 0) return memo[n][k];
+ ll res = n/primes[k] - phi(n/primes[k], k - 1) + phi(n, k - 1);
+ if (ok) memo[n][k] = res;
+ return res;
+}
+
+ll pi(ll n) {
+ if (n < N) { // implement this as O(1) lookup for speedup!
+ return ranges::upper_bound(primes, n) - begin(primes);
+ } else {
+ ll k = pi(sqrtl(n) + 1);
+ return n - phi(n, k) + k;
+}}
diff --git a/content/math/polynomial.cpp b/content/math/polynomial.cpp
index 84f3aaa..12a4fd7 100644
--- a/content/math/polynomial.cpp
+++ b/content/math/polynomial.cpp
@@ -4,15 +4,15 @@ struct poly {
poly(int deg = 0) : data(1 + deg) {}
poly(initializer_list<ll> _data) : data(_data) {}
- int size() const {return sz(data);}
+ int size() const { return ssize(data); }
void trim() {
for (ll& x : data) x = (x % mod + mod) % mod;
while (size() > 1 && data.back() == 0) data.pop_back();
}
- ll& operator[](int x) {return data[x];}
- const ll& operator[](int x) const {return data[x];}
+ ll& operator[](int x) { return data[x]; }
+ const ll& operator[](int x) const { return data[x]; }
ll operator()(int x) const {
ll res = 0;
diff --git a/content/math/primeSieve.cpp b/content/math/primeSieve.cpp
index 1b0f514..2b2bf26 100644
--- a/content/math/primeSieve.cpp
+++ b/content/math/primeSieve.cpp
@@ -8,7 +8,7 @@ bool isPrime(ll x) {
}
void primeSieve() {
- for (ll i = 3; i < N; i += 2) {// i * i < N reicht für isPrime
+ for (ll i = 3; i < N; i += 2) { // i * i < N reicht für isPrime
if (!isNotPrime[i / 2]) {
primes.push_back(i); // optional
for (ll j = i * i; j < N; j+= 2 * i) {
diff --git a/content/math/recover.cpp b/content/math/recover.cpp
index 1a593f0..a4c22aa 100644
--- a/content/math/recover.cpp
+++ b/content/math/recover.cpp
@@ -1,4 +1,4 @@
-ll sq(ll x) {return x*x;}
+ll sq(ll x) { return x*x; }
array<ll, 2> recover(ll c, ll m) {
array<ll, 2> u = {m, 0}, v = {c, 1};
diff --git a/content/math/rho.cpp b/content/math/rho.cpp
index ad640cd..c7f7a70 100644
--- a/content/math/rho.cpp
+++ b/content/math/rho.cpp
@@ -2,7 +2,7 @@ using lll = __int128;
ll rho(ll n) { // Findet Faktor < n, nicht unbedingt prim.
if (n % 2 == 0) return 2;
ll x = 0, y = 0, prd = 2, i = n/2 + 7;
- auto f = [&](lll c){return (c * c + i) % n;};
+ auto f = [&](lll c) { return (c * c + i) % n; };
for (ll t = 30; t % 40 || gcd(prd, n) == 1; t++) {
if (x == y) x = ++i, y = f(x);
if (ll q = (lll)prd * abs(x-y) % n; q) prd = q;
@@ -13,7 +13,7 @@ ll rho(ll n) { // Findet Faktor < n, nicht unbedingt prim.
void factor(ll n, map<ll, int>& facts) {
if (n == 1) return;
- if (isPrime(n)) {facts[n]++; return;}
+ if (isPrime(n)) { facts[n]++; return; }
ll f = rho(n);
factor(n / f, facts); factor(f, facts);
}
diff --git a/content/math/shortModInv.cpp b/content/math/shortModInv.cpp
index cf91ca0..7d3002c 100644
--- a/content/math/shortModInv.cpp
+++ b/content/math/shortModInv.cpp
@@ -1,3 +1,3 @@
ll multInv(ll x, ll m) { // x^{-1} mod m
- return 1 < x ? m - multInv(m % x, x) * m / x : 1;
+ return 1 < (x %= m) ? m - multInv(m, x) * m / x : 1;
}
diff --git a/content/math/simpson.cpp b/content/math/simpson.cpp
index 7f237a4..da9c002 100644
--- a/content/math/simpson.cpp
+++ b/content/math/simpson.cpp
@@ -1,4 +1,4 @@
-//double f(double x) {return x;}
+//double f(double x) { return x; }
double simps(double a, double b) {
return (f(a) + 4.0 * f((a + b) / 2.0) + f(b)) * (b - a) / 6.0;
diff --git a/content/math/sqrtModCipolla.cpp b/content/math/sqrtModCipolla.cpp
index 1fac0c5..c062646 100644
--- a/content/math/sqrtModCipolla.cpp
+++ b/content/math/sqrtModCipolla.cpp
@@ -1,4 +1,4 @@
-ll sqrtMod(ll a, ll p) {// teste mit legendre ob lösung existiert
+ll sqrtMod(ll a, ll p) {// teste mit Legendre ob Lösung existiert
if (a < 2) return a;
ll t = 0;
while (legendre((t*t-4*a) % p, p) >= 0) t = rng() % p;
diff --git a/content/math/tables/composite.tex b/content/math/tables/composite.tex
deleted file mode 100644
index 7a6ab09..0000000
--- a/content/math/tables/composite.tex
+++ /dev/null
@@ -1,26 +0,0 @@
-\begin{expandtable}
-\begin{tabularx}{\linewidth}{|r||r|R||r||r|}
- \hline
- $10^x$ & Highly Composite & \# Divs & \# prime Divs & \# Primes \\
- \hline
- 1 & 6 & 4 & 2 & 4 \\
- 2 & 60 & 12 & 3 & 25 \\
- 3 & 840 & 32 & 4 & 168 \\
- 4 & 7\,560 & 64 & 5 & 1\,229 \\
- 5 & 83\,160 & 128 & 6 & 9\,592 \\
- 6 & 720\,720 & 240 & 7 & 78\,498 \\
- 7 & 8\,648\,640 & 448 & 8 & 664\,579 \\
- 8 & 73\,513\,440 & 768 & 8 & 5\,761\,455 \\
- 9 & 735\,134\,400 & 1\,344 & 9 & 50\,847\,534 \\
- 10 & 6\,983\,776\,800 & 2\,304 & 10 & 455\,052\,511 \\
- 11 & 97\,772\,875\,200 & 4\,032 & 10 & 4\,118\,054\,813 \\
- 12 & 963\,761\,198\,400 & 6\,720 & 11 & 37\,607\,912\,018 \\
- 13 & 9\,316\,358\,251\,200 & 10\,752 & 12 & 346\,065\,536\,839 \\
- 14 & 97\,821\,761\,637\,600 & 17\,280 & 12 & 3\,204\,941\,750\,802 \\
- 15 & 866\,421\,317\,361\,600 & 26\,880 & 13 & 29\,844\,570\,422\,669 \\
- 16 & 8\,086\,598\,962\,041\,600 & 41\,472 & 13 & 279\,238\,341\,033\,925 \\
- 17 & 74\,801\,040\,398\,884\,800 & 64\,512 & 14 & 2\,623\,557\,157\,654\,233 \\
- 18 & 897\,612\,484\,786\,617\,600 & 103\,680 & 16 & 24\,739\,954\,287\,740\,860 \\
- \hline
-\end{tabularx}
-\end{expandtable}
diff --git a/content/math/tables/prime-composite.tex b/content/math/tables/prime-composite.tex
new file mode 100644
index 0000000..b8adadf
--- /dev/null
+++ b/content/math/tables/prime-composite.tex
@@ -0,0 +1,31 @@
+\begin{expandtable}
+\begin{tabularx}{\linewidth}{|r|rIr|rIr|r|R|}
+ \hline
+ \multirow{2}{*}{$10^x$}
+ & \multirow{2}{*}{Highly Composite}
+ & \multirow{2}{*}{\# Divs}
+ & \multicolumn{2}{c|}{Prime}
+ & \multirow{2}{*}{\# Primes} & \# Prime \\
+ & & & $<$ & $>$ & & Factors \\
+ \hline
+ 1 & 6 & 4 & $-3$ & $+1$ & 4 & 2 \\
+ 2 & 60 & 12 & $-3$ & $+1$ & 25 & 3 \\
+ 3 & 840 & 32 & $-3$ & $+9$ & 168 & 4 \\
+ 4 & 7\,560 & 64 & $-27$ & $+7$ & 1\,229 & 5 \\
+ 5 & 83\,160 & 128 & $-9$ & $+3$ & 9\,592 & 6 \\
+ 6 & 720\,720 & 240 & $-17$ & $+3$ & 78\,498 & 7 \\
+ 7 & 8\,648\,640 & 448 & $-9$ & $+19$ & 664\,579 & 8 \\
+ 8 & 73\,513\,440 & 768 & $-11$ & $+7$ & 5\,761\,455 & 8 \\
+ 9 & 735\,134\,400 & 1\,344 & $-63$ & $+7$ & 50\,847\,534 & 9 \\
+ 10 & 6\,983\,776\,800 & 2\,304 & $-33$ & $+19$ & 455\,052\,511 & 10 \\
+ 11 & 97\,772\,875\,200 & 4\,032 & $-23$ & $+3$ & 4\,118\,054\,813 & 10 \\
+ 12 & 963\,761\,198\,400 & 6\,720 & $-11$ & $+39$ & 37\,607\,912\,018 & 11 \\
+ 13 & 9\,316\,358\,251\,200 & 10\,752 & $-29$ & $+37$ & 346\,065\,536\,839 & 12 \\
+ 14 & 97\,821\,761\,637\,600 & 17\,280 & $-27$ & $+31$ & 3\,204\,941\,750\,802 & 12 \\
+ 15 & 866\,421\,317\,361\,600 & 26\,880 & $-11$ & $+37$ & 29\,844\,570\,422\,669 & 13 \\
+ 16 & 8\,086\,598\,962\,041\,600 & 41\,472 & $-63$ & $+61$ & 279\,238\,341\,033\,925 & 13 \\
+ 17 & 74\,801\,040\,398\,884\,800 & 64\,512 & $-3$ & $+3$ & 2\,623\,557\,157\,654\,233 & 14 \\
+ 18 & 897\,612\,484\,786\,617\,600 & 103\,680 & $-11$ & $+3$ & 24\,739\,954\,287\,740\,860 & 15 \\
+ \hline
+\end{tabularx}
+\end{expandtable}
diff --git a/content/math/transforms/andTransform.cpp b/content/math/transforms/andTransform.cpp
index 1fd9f5c..9e40c74 100644
--- a/content/math/transforms/andTransform.cpp
+++ b/content/math/transforms/andTransform.cpp
@@ -1,8 +1,8 @@
void fft(vector<ll>& a, bool inv = false) {
- int n = sz(a);
+ int n = ssize(a);
for (int s = 1; s < n; s *= 2) {
for (int i = 0; i < n; i += 2 * s) {
for (int j = i; j < i + s; j++) {
ll& u = a[j], &v = a[j + s];
- tie(u, v) = inv ? pair(v - u, u) : pair(v, u + v);
+ tie(u, v) = inv ? pair(u - v, v) : pair(u + v, v);
}}}}
diff --git a/content/math/transforms/bitwiseTransforms.cpp b/content/math/transforms/bitwiseTransforms.cpp
index 28561da..17f3163 100644
--- a/content/math/transforms/bitwiseTransforms.cpp
+++ b/content/math/transforms/bitwiseTransforms.cpp
@@ -1,11 +1,11 @@
void bitwiseConv(vector<ll>& a, bool inv = false) {
- int n = sz(a);
+ int n = ssize(a);
for (int s = 1; s < n; s *= 2) {
for (int i = 0; i < n; i += 2 * s) {
for (int j = i; j < i + s; j++) {
ll& u = a[j], &v = a[j + s];
- tie(u, v) = inv ? pair(v - u, u) : pair(v, u + v); // AND
- //tie(u, v) = inv ? pair(v, u - v) : pair(u + v, u); //OR
+ tie(u, v) = inv ? pair(u - v, v) : pair(u + v, v); // AND
+ //tie(u, v) = inv ? pair(u, v - u) : pair(u, v + u); //OR
//tie(u, v) = pair(u + v, u - v); // XOR
}}}
//if (inv) for (ll& x : a) x /= n; // XOR (careful with MOD)
diff --git a/content/math/transforms/fft.cpp b/content/math/transforms/fft.cpp
index 2bd95b2..1f80e36 100644
--- a/content/math/transforms/fft.cpp
+++ b/content/math/transforms/fft.cpp
@@ -1,7 +1,7 @@
using cplx = complex<double>;
void fft(vector<cplx>& a, bool inv = false) {
- int n = sz(a);
+ int n = ssize(a);
for (int i = 0, j = 1; j < n - 1; ++j) {
for (int k = n >> 1; k > (i ^= k); k >>= 1);
if (j < i) swap(a[i], a[j]);
diff --git a/content/math/transforms/fftMul.cpp b/content/math/transforms/fftMul.cpp
index 660ed79..da6a538 100644
--- a/content/math/transforms/fftMul.cpp
+++ b/content/math/transforms/fftMul.cpp
@@ -1,8 +1,8 @@
vector<cplx> mul(vector<ll>& a, vector<ll>& b) {
- int n = 1 << (__lg(sz(a) + sz(b) - 1) + 1);
- vector<cplx> c(all(a)), d(n);
+ int n = 1 << (__lg(ssize(a) + ssize(b) - 1) + 1);
+ vector<cplx> c(begin(a), end(a)), d(n);
c.resize(n);
- for (int i = 0; i < sz(b); i++) c[i] = {real(c[i]), b[i]};
+ for (int i = 0; i < ssize(b); i++) c[i] = {real(c[i]), b[i]};
fft(c);
for (int i = 0; i < n; i++) {
int j = (n - i) & (n - 1);
diff --git a/content/math/transforms/multiplyBitwise.cpp b/content/math/transforms/multiplyBitwise.cpp
index f7cf169..5275b8c 100644
--- a/content/math/transforms/multiplyBitwise.cpp
+++ b/content/math/transforms/multiplyBitwise.cpp
@@ -1,5 +1,5 @@
vector<ll> mul(vector<ll> a, vector<ll> b) {
- int n = 1 << (__lg(2 * max(sz(a), sz(b)) - 1));
+ int n = 1 << (__lg(2 * max(ssize(a), ssize(b)) - 1));
a.resize(n), b.resize(n);
bitwiseConv(a), bitwiseConv(b);
for (int i=0; i<n; i++) a[i] *= b[i]; // MOD?
diff --git a/content/math/transforms/multiplyFFT.cpp b/content/math/transforms/multiplyFFT.cpp
index 0022d1f..963be94 100644
--- a/content/math/transforms/multiplyFFT.cpp
+++ b/content/math/transforms/multiplyFFT.cpp
@@ -1,6 +1,6 @@
vector<ll> mul(vector<ll>& a, vector<ll>& b) {
- int n = 1 << (__lg(sz(a) + sz(b) - 1) + 1);
- vector<cplx> a2(all(a)), b2(all(b));
+ int n = 1 << (__lg(ssize(a) + ssize(b) - 1) + 1);
+ vector<cplx> a2(begin(a), end(a)), b2(begin(b), end(b));
a2.resize(n), b2.resize(n);
fft(a2), fft(b2);
for (int i=0; i<n; i++) a2[i] *= b2[i];
diff --git a/content/math/transforms/multiplyNTT.cpp b/content/math/transforms/multiplyNTT.cpp
index 806d124..d234ce3 100644
--- a/content/math/transforms/multiplyNTT.cpp
+++ b/content/math/transforms/multiplyNTT.cpp
@@ -1,5 +1,5 @@
vector<ll> mul(vector<ll> a, vector<ll> b) {
- int n = 1 << (__lg(sz(a) + sz(b) - 1) + 1);
+ int n = 1 << bit_width(size(a) + size(b) - 1);
a.resize(n), b.resize(n);
ntt(a), ntt(b);
for (int i=0; i<n; i++) a[i] = a[i] * b[i] % mod;
diff --git a/content/math/transforms/ntt.cpp b/content/math/transforms/ntt.cpp
index ca605d3..fc7874e 100644
--- a/content/math/transforms/ntt.cpp
+++ b/content/math/transforms/ntt.cpp
@@ -1,7 +1,7 @@
constexpr ll mod = 998244353, root = 3;
void ntt(vector<ll>& a, bool inv = false) {
- int n = sz(a);
+ int n = ssize(a);
auto b = a;
ll r = inv ? powMod(root, mod - 2, mod) : root;
diff --git a/content/math/transforms/orTransform.cpp b/content/math/transforms/orTransform.cpp
index eb1da44..6503a68 100644
--- a/content/math/transforms/orTransform.cpp
+++ b/content/math/transforms/orTransform.cpp
@@ -1,8 +1,8 @@
void fft(vector<ll>& a, bool inv = false) {
- int n = sz(a);
+ int n = ssize(a);
for (int s = 1; s < n; s *= 2) {
for (int i = 0; i < n; i += 2 * s) {
for (int j = i; j < i + s; j++) {
ll& u = a[j], &v = a[j + s];
- tie(u, v) = inv ? pair(v, u - v) : pair(u + v, u);
+ tie(u, v) = inv ? pair(u, v - u) : pair(u, v + u);
}}}}
diff --git a/content/math/transforms/seriesOperations.cpp b/content/math/transforms/seriesOperations.cpp
index b405698..3d8aa11 100644
--- a/content/math/transforms/seriesOperations.cpp
+++ b/content/math/transforms/seriesOperations.cpp
@@ -17,7 +17,7 @@ vector<ll> poly_inv(const vector<ll>& a, int n) {
}
vector<ll> poly_deriv(vector<ll> a) {
- for (int i = 1; i < sz(a); i++)
+ for (int i = 1; i < ssize(a); i++)
a[i-1] = a[i] * i % mod;
a.pop_back();
return a;
@@ -25,11 +25,11 @@ vector<ll> poly_deriv(vector<ll> a) {
vector<ll> poly_integr(vector<ll> a) {
static vector<ll> inv = {0, 1};
- for (static int i = 2; i <= sz(a); i++)
+ for (static int i = 2; i <= ssize(a); i++)
inv.push_back(mod - mod / i * inv[mod % i] % mod);
a.push_back(0);
- for (int i = sz(a) - 1; i > 0; i--)
+ for (int i = ssize(a) - 1; i > 0; i--)
a[i] = a[i-1] * inv[i] % mod;
a[0] = 0;
return a;
@@ -46,7 +46,7 @@ vector<ll> poly_exp(vector<ll> a, int n) {
for (int len = 1; len < n; len *= 2) {
vector<ll> p = poly_log(q, 2*len);
for (int i = 0; i < 2*len; i++)
- p[i] = (mod - p[i] + (i < sz(a) ? a[i] : 0)) % mod;
+ p[i] = (mod - p[i] + (i < ssize(a) ? a[i] : 0)) % mod;
vector<ll> q2 = q;
q2.resize(2*len);
ntt(p), ntt(q2);
diff --git a/content/math/transforms/xorTransform.cpp b/content/math/transforms/xorTransform.cpp
index f9d1d82..075aac3 100644
--- a/content/math/transforms/xorTransform.cpp
+++ b/content/math/transforms/xorTransform.cpp
@@ -1,5 +1,5 @@
void fft(vector<ll>& a, bool inv = false) {
- int n = sz(a);
+ int n = ssize(a);
for (int s = 1; s < n; s *= 2) {
for (int i = 0; i < n; i += 2 * s) {
for (int j = i; j < i + s; j++) {