diff options
Diffstat (limited to 'content/math')
40 files changed, 246 insertions, 237 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 deleted file mode 100644 index a1c63c8..0000000 --- a/content/math/gcd-lcm.cpp +++ /dev/null @@ -1,2 +0,0 @@ -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/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..7764d54 100644 --- a/content/math/math.tex +++ b/content/math/math.tex @@ -26,21 +26,24 @@ \end{methods}
\sourcecode{math/permIndex.cpp}
\end{algorithm}
-\clearpage
-
-\subsection{Mod-Exponent und Multiplikation über $\boldsymbol{\mathbb{F}_p}$}
-%\vspace{-1.25em}
-%\begin{multicols}{2}
-\method{mulMod}{berechnet $a \cdot b \bmod n$}{\log(b)}
-\sourcecode{math/modMulIterativ.cpp}
-% \vfill\null\columnbreak
-\method{powMod}{berechnet $a^b \bmod n$}{\log(b)}
-\sourcecode{math/modPowIterativ.cpp}
-%\end{multicols}
-%\vspace{-2.75em}
-\begin{itemize}
- \item für $a > 10^9$ \code{__int128} oder \code{modMul} benutzten!
-\end{itemize}
+\columnbreak
+
+\subsection{Potenzen in $\boldsymbol{\mathbb{Z}/n\mathbb{Z}}$}
+ \begin{methods}
+ \method{powMod}{berechnet $a^b \bmod n$}{\log(b)}
+ \end{methods}
+ \sourcecode{math/modPowIterativ.cpp}
+ \begin{itemize}
+ \item für $a > 10^9$ \code{__int128} oder \code{modMul} benutzten!
+ \end{itemize}
+
+\optional{
+\subsection{Multiplikation in $\boldsymbol{\mathbb{Z}/n\mathbb{Z}}$ \opthint}
+ \begin{methods}
+ \method{mulMod}{berechnet $a \cdot b \bmod n$}{\log(b)}
+ \end{methods}
+ \sourcecode{math/modMulIterativ.cpp}
+}
\begin{algorithm}{ggT, kgV, erweiterter euklidischer Algorithmus}
\runtime{\log(a) + \log(b)}
@@ -100,8 +103,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 +124,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 +239,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 +253,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 +266,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,21 +324,27 @@ 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$.
+ \ifthenelse{\isundefined{\srclink}}{}{%
+ \hfill
+ \begin{ocg}[printocg=never]{Source links}{srclinks}{1}%
+ \href{\srclink{math/transforms/}}{\faExternalLink}%
+ \end{ocg}%
+ }
\begin{itemize}
\item $\deg(A \cdot B) = \deg(A) + \deg(B)$
\item Vektoren \code{a} und \code{b} müssen mindestens Größe
$\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 +354,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 +366,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}
@@ -390,16 +399,19 @@ so gilt \end{methods}
\sourcecode{math/binomial1.cpp}
+ \optional{
+ \begin{methods}
+ \method{calc\_binom}{berechnet Primfaktoren vom Binomialkoeffizient}{n\*\log(n)}
+ \end{methods}
+ \opthint \\
+ \textbf{WICHTIG:} braucht alle Primzahlen $\leq n$
+ \sourcecode{math/binomial2.cpp}
+ }
+
\begin{methods}
\method{calc\_binom}{berechnet Binomialkoeffizient modulo Primzahl $p$}{p-n}
\end{methods}
\sourcecode{math/binomial3.cpp}
-
-% \begin{methods}
-% \method{calc\_binom}{berechnet Primfaktoren vom Binomialkoeffizient}{n}
-% \end{methods}
-% \textbf{WICHTIG:} braucht alle Primzahlen $\leq n$
-% \sourcecode{math/binomial2.cpp}
%\end{algorithm}
\paragraph{\textsc{Catalan}-Zahlen}
@@ -415,7 +427,7 @@ so gilt \end{itemize}
\end{itemize}
\[C_0 = 1\qquad C_n = \sum\limits_{k = 0}^{n - 1} C_kC_{n - 1 - k} =
-\frac{1}{n + 1}\binom{2n}{n} = \frac{4n - 2}{n+1} \cdot C_{n-1}\]
+\frac{1}{n + 1}\binom{2n}{n} = \frac{4n - 2}{n+1} C_{n-1} \sim \frac{4^n}{n^{3/2} \sqrt{\pi}}\]
\begin{itemize}
\item Formel $1$ erlaubt Berechnung ohne Division in \runtime{n^2}
\item Formel $2$ und $3$ erlauben Berechnung in \runtime{n}
@@ -426,70 +438,70 @@ so gilt \item Anzahl an Klammerausdrücken mit $n+k$ Klammerpaaren, die mit $(^k$ beginnen.
\end{itemize}
\[C^k_0 = 1\qquad C^k_n = \sum\limits_{\mathclap{a_0+a_1+\dots+a_k=n}} C_{a_0}C_{a_1}\cdots C_{a_k} =
-\frac{k+1}{n+k+1}\binom{2n+k}{n} = \frac{(2n+k-1)\cdot(2n+k)}{n(n+k+1)} \cdot C_{n-1}\]
+\frac{k+1}{n+k+1}\binom{2n+k}{n} = \frac{(2n+k-1)(2n+k)}{n(n+k+1)} C_{n-1}\]
-\paragraph{\textsc{Euler}-Zahlen 1. Ordnung}
+\paragraph{\textsc{Euler}-Zahlen}
Die Anzahl der Permutationen von $\{1, \ldots, n\}$ mit genau $k$ Anstiegen.
Für die $n$-te Zahl gibt es $n$ mögliche Positionen zum Einfügen.
Dabei wird entweder ein Anstieg in zwei gesplitted oder ein Anstieg um $n$ ergänzt.
\[\eulerI{n}{0} = \eulerI{n}{n-1} = 1 \quad
-\eulerI{n}{k} = (k+1) \eulerI{n-1}{k} + (n-k) \eulerI{n-1}{k-1}=
-\sum_{i=0}^{k} (-1)^i\binom{n+1}{i}(k+1-i)^n\]
-\begin{itemize}
- \item Formel $1$ erlaubt Berechnung ohne Division in \runtime{n^2}
- \item Formel $2$ erlaubt Berechnung in \runtime{n\log(n)}
-\end{itemize}
-
-\paragraph{\textsc{Euler}-Zahlen 2. Ordnung}
-Die Anzahl der Permutationen von $\{1,1, \ldots, n,n\}$ mit genau $k$ Anstiegen.
-\[\eulerII{n}{0} = 1 \qquad\eulerII{n}{n} = 0 \qquad\eulerII{n}{k} = (k+1) \eulerII{n-1}{k} + (2n-k-1) \eulerII{n-1}{k-1}\]
-\begin{itemize}
- \item Formel erlaubt Berechnung ohne Division in \runtime{n^2}
-\end{itemize}
+\eulerI{n}{k} = (k+1) \eulerI{n-1}{k} + (n-k) \eulerI{n-1}{k-1}\]
+\[
+\eulerI{n}{k} = [x^k]
+ \left(\sum_{i=0}^\infty (i+1)^n x^i\right)
+ \left(\sum_{i=0}^\infty (-1)^i \binom{n+1}{i} x^i\right)
+\]
-\paragraph{\textsc{Stirling}-Zahlen 1. Ordnung}
+\paragraph{\textsc{Stirling}-Zahlen 1. Art}
Die Anzahl der Permutationen von $\{1, \ldots, n\}$ mit genau $k$ Zyklen.
-Es gibt zwei Möglichkeiten für die $n$-te Zahl. Entweder sie bildet einen eigene Zyklus, oder sie kann an jeder Position in jedem Zyklus einsortiert werden.
+Es gibt zwei Möglichkeiten für die $n$-te Zahl. Entweder sie bildet einen eigenen Zyklus, oder sie kann an jeder Position in jedem Zyklus einsortiert werden.
\[\stirlingI{0}{0} = 1 \qquad
\stirlingI{n}{0} = \stirlingI{0}{n} = 0 \qquad
\stirlingI{n}{k} = \stirlingI{n-1}{k-1} + (n-1) \stirlingI{n-1}{k}\]
-\begin{itemize}
- \item Formel erlaubt berechnung ohne Division in \runtime{n^2}
-\end{itemize}
-\[\sum_{k=0}^{n}\pm\stirlingI{n}{k}x^k=x(x-1)(x-2)\cdots(x-n+1)\]
-\begin{itemize}
- \item Berechne Polynom mit FFT und benutzte betrag der Koeffizienten \runtime{n\log(n)^2} (nur ungefähr gleich große Polynome zusammen multiplizieren beginnend mit $x-k$)
-\end{itemize}
+\[
+\stirlingI{n}{k}
+= [x^k]\prod_{i=0}^{n-1} (x+i)
+= n! [x^{n-k}] \frac{1}{k!} \left(\sum_{i=0}^\infty \frac{1}{i+1}x^i\right)^k
+\]
-\paragraph{\textsc{Stirling}-Zahlen 2. Ordnung}
+\paragraph{\textsc{Stirling}-Zahlen 2. Art}
Die Anzahl der Möglichkeiten $n$ Elemente in $k$ nichtleere Teilmengen zu zerlegen.
Es gibt $k$ Möglichkeiten die $n$ in eine $n-1$-Partition einzuordnen.
Dazu kommt der Fall, dass die $n$ in ihrer eigenen Teilmenge (alleine) steht.
\[\stirlingII{n}{1} = \stirlingII{n}{n} = 1 \qquad
-\stirlingII{n}{k} = k \stirlingII{n-1}{k} + \stirlingII{n-1}{k-1} =
-\frac{1}{k!} \sum\limits_{i=0}^{k} (-1)^{k-i}\binom{k}{i}i^n\]
-\begin{itemize}
- \item Formel $1$ erlaubt Berechnung ohne Division in \runtime{n^2}
- \item Formel $2$ erlaubt Berechnung in \runtime{n\log(n)}
-\end{itemize}
+\stirlingII{n}{k} = k \stirlingII{n-1}{k} + \stirlingII{n-1}{k-1}
+\]
+\[
+\stirlingII{n}{k}
+= [x^k]
+ \left(\sum_{i=0}^\infty \frac{i^n}{i!}x^i\right)
+ \left(\sum_{i=0}^\infty \frac{(-1)^i}{i!}x^i\right)
+= n! [x^{n-k}] \frac{1}{k!} \left(\sum_{i=0}^\infty \frac{1}{(i+1)!}x^i\right)^k
+\]
\paragraph{\textsc{Bell}-Zahlen}
Anzahl der Partitionen von $\{1, \ldots, n\}$.
-Wie \textsc{Stirling}-Zahlen 2. Ordnung ohne Limit durch $k$.
+Wie \textsc{Stirling}-Zahlen 2. Art ohne Limit durch $k$.
\[B_1 = 1 \qquad
B_n = \sum\limits_{k = 0}^{n - 1} B_k\binom{n-1}{k}
-= \sum\limits_{k = 0}^{n}\stirlingII{n}{k}\qquad\qquad B_{p^m+n}\equiv m\cdot B_n + B_{n+1} \bmod{p}\]
+= \sum\limits_{k = 0}^{n}\stirlingII{n}{k}
+= n! [x^n] e^{e^x-1}
+\qquad
+B_{p^m+n}\equiv m\cdot B_n + B_{n+1} \bmod{p}\]
\paragraph{Partitions}
Die Anzahl der Partitionen von $n$ in genau $k$ positive Summanden.
Die Anzahl der Partitionen von $n$ mit Elementen aus ${1,\dots,k}$.
\begin{align*}
p_0(0)=1 \qquad p_k(n)&=0 \text{ für } k > n \text{ oder } n \leq 0 \text{ oder } k \leq 0\\
- p_k(n)&= p_k(n-k) + p_{k-1}(n-1)\\[2pt]
- p(n)=\sum_{k=1}^{n} p_k(n)&=p_n(2n)=\sum\limits_{k=1}^\infty(-1)^{k+1}\bigg[p\bigg(n - \frac{k(3k-1)}{2}\bigg) + p\bigg(n - \frac{k(3k+1)}{2}\bigg)\bigg]
+ p_k(n)&= p_k(n-k) + p_{k-1}(n-1)\\
+ p(n)=\sum_{k=1}^{n} p_k(n)&=p_n(2n)=\sum\limits_{k=1}^\infty(-1)^{k+1}\bigg[p\bigg(n - \frac{k(3k-1)}{2}\bigg) + p\bigg(n - \frac{k(3k+1)}{2}\bigg)\bigg] \\
+ p(n)&=[x^n] \left(\sum_{k=-\infty}^\infty (-1)^k x^{k(3k-1)/2}\right)^{-1}
+ \sim \frac{1}{4 \sqrt{3} n} \exp\left(\pi \sqrt{\frac{2n}{3}}\right)
\end{align*}
\begin{itemize}
\item in Formel $3$ kann abgebrochen werden wenn $\frac{k(3k-1)}{2} > n$.
+ $\rightarrow$ \runtime{n \sqrt{n}}
\item Die Anzahl der Partitionen von $n$ in bis zu $k$ positive Summanden ist $\sum\limits_{i=0}^{k}p_i(n)=p_k(n+k)$.
\end{itemize}
@@ -542,10 +554,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/modExp.cpp b/content/math/modExp.cpp deleted file mode 100644 index 2329a94..0000000 --- a/content/math/modExp.cpp +++ /dev/null @@ -1,6 +0,0 @@ -ll powMod(ll a, ll b, ll n) { - if(b == 0) return 1; - if(b == 1) return a % n; - if(b & 1) return (powMod(a, b - 1, n) * a) % n; - else return powMod((a * a) % n, b / 2, n); -} 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/nim.tex b/content/math/tables/nim.tex index 66e289e..3c36bbb 100644 --- a/content/math/tables/nim.tex +++ b/content/math/tables/nim.tex @@ -1,3 +1,4 @@ +In jedem Zug, wähle $m \in M$ und nimm $m$ Objekte. \begin{expandtable} \begin{tabularx}{\linewidth}{|p{0.37\linewidth}|X|} \hline @@ -84,14 +85,12 @@ $\mathit{SG}_n = n - 1$, falls $n \equiv 0 \bmod 4$\\ \hline - \textsc{Kayles}' Nim:\newline - Zwei mögliche Züge:\newline - 1) Nehme beliebige Zahl.\newline - 2) Teile Stapel in zwei Stapel (mit Entnahme).& + Kayles:\newline + Nimm 1 oder 2, dann teile den Stapel optional in zwei Stapel.& Berechne $\mathit{SG}_n$ für kleine $n$ rekursiv.\newline $n \in [72,83]: \quad 4, 1, 2, 8, 1, 4, 7, 2, 1, 8, 2, 7$\newline Periode ab $n = 72$ der Länge $12$.\\ \hline \end{tabularx} \end{expandtable} -
\ No newline at end of file + 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++) { |
