diff options
| author | Yidi <noob999noob999@gmail.com> | 2025-06-06 15:21:51 +0200 |
|---|---|---|
| committer | Yidi <noob999noob999@gmail.com> | 2025-06-06 15:21:51 +0200 |
| commit | aca95353f22fb48fab74bf45de85f8badaa2e274 (patch) | |
| tree | 374d0caba4a46d1ec6699a417b1ce5e8182134ca | |
| parent | 14a5aa119dd90c4764c47b00f141117b0193b73e (diff) | |
improve gauss + fix latex
| -rw-r--r-- | content/math/lgsFp.cpp | 26 | ||||
| -rw-r--r-- | content/other/other.tex | 10 | ||||
| -rw-r--r-- | tcr.pdf | bin | 698689 -> 685349 bytes | |||
| -rw-r--r-- | test/math/lgsFp.cpp | 13 |
4 files changed, 21 insertions, 28 deletions
diff --git a/content/math/lgsFp.cpp b/content/math/lgsFp.cpp index a4f3d0f..a8d7fc7 100644 --- a/content/math/lgsFp.cpp +++ b/content/math/lgsFp.cpp @@ -1,20 +1,20 @@ -vector<int> piv; -void gauss(){ - for(int r = 0, c = 0; c < m; c++){ - for(int i = r; i < n; i++){ - if(mat[i][c] != 0){ +vector<int> pivots; // ith pivot is in ith row +void gauss(int n, int m) { + for (int r = 0, c = 0; c < m; c++) { + for (int i = r; i < n; i++) { + if (mat[i][c] != 0){ swap(mat[r], mat[i]); break; }} - if(mat[r][c] == 0) continue; + if (mat[r][c] == 0) continue; ll f = multInv(mat[r][c], mod); - for(ll &x : mat[r]) x = x * f % mod; - for(int i = 0; i < n; i++){ - if(i == r) continue; + for (ll& x : mat[r]) x = x * f % mod; + for (int i = 0; i < n; i++) { + if (i == r) continue; f = mat[i][c]; - for(int j = c; j < sz(mat[r]); j++){ + for (int j = c; j < m; j++) { mat[i][j] = (mat[i][j] - f * mat[r][j] % mod + mod) % mod; }} - piv.push_back(c); - if(++r == n) break; -}}
\ No newline at end of file + pivots.push_back(c); + if (++r == n) break; +}} // no solution if pivots.back() == m-1 diff --git a/content/other/other.tex b/content/other/other.tex index a38f6da..a5004fb 100644 --- a/content/other/other.tex +++ b/content/other/other.tex @@ -18,9 +18,9 @@ \begin{expandtable}
\begin{tabularx}{\linewidth}{|lR|}
\hline
- Addition & \code{__builtin_saddll_overflow(a, b, &c)} \\
- Subtraktion & \code{__builtin_ssubll_overflow(a, b, &c)} \\
- Multiplikation & \code{__builtin_smulll_overflow(a, b, &c)} \\
+ Addition & \code{__builtin_saddll_overflow(a, b, \&c)} \\
+ Subtraktion & \code{__builtin_ssubll_overflow(a, b, \&c)} \\
+ Multiplikation & \code{__builtin_smulll_overflow(a, b, \&c)} \\
\hline
\end{tabularx}
\end{expandtable}
@@ -30,9 +30,9 @@ \begin{expandtable}
\begin{tabularx}{\linewidth}{|Ll|}
\hline
- Bit an Position j lesen & \code{(x & (1 << j)) != 0} \\
+ Bit an Position j lesen & \code{(x \& (1 << j)) != 0} \\
Bit an Position j setzten & \code{x |= (1 << j)} \\
- Bit an Position j löschen & \code{x &= ~(1 << j)} \\
+ Bit an Position j löschen & \code{x \&= ~(1 << j)} \\
Bit an Position j flippen & \code{x ^= (1 << j)} \\
Anzahl an führenden nullen ($x \neq 0$) & \code{__builtin_clzll(x)} \\
Anzahl an schließenden nullen ($x \neq 0$) & \code{__builtin_ctzll(x)} \\
Binary files differdiff --git a/test/math/lgsFp.cpp b/test/math/lgsFp.cpp index e529390..d7680ea 100644 --- a/test/math/lgsFp.cpp +++ b/test/math/lgsFp.cpp @@ -3,7 +3,6 @@ vector<vector<ll>> mat; constexpr ll mod = 1'000'000'007; namespace lgs { - int n, m; #include <math/lgsFp.cpp> } @@ -16,9 +15,7 @@ vector<vector<ll>> inverseMat(const vector<vector<ll>>& m) { mat[i].resize(2*n); mat[i][n+i] = 1; } - lgs::n = sz(mat); - lgs::m = sz(mat[0]); - lgs::gauss(); + lgs::gauss(sz(mat), sz(mat[0])); vector<vector<ll>> res(m); for (int i = 0; i < n; i++) { res[i] = vector<ll>(mat[i].begin() + n, mat[i].end()); @@ -57,9 +54,7 @@ void test_square() { vector<vector<ll>> m(n); for (auto& v : m) v = Random::integers<ll>(n, 0, mod); mat = m; - lgs::n = sz(mat); - lgs::m = sz(mat[0]); - lgs::gauss(); + lgs::gauss(sz(mat), sz(mat[0])); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { @@ -104,11 +99,9 @@ void performance_test() { vector<vector<ll>> m(N); for (auto& v : m) v = Random::integers<ll>(N, 0, mod); mat = m; - lgs::n = sz(mat); - lgs::m = sz(mat[0]); t.start(); - lgs::gauss(); + lgs::gauss(sz(mat), sz(mat[0])); t.stop(); hash_t hash = 0; for (int i = 0; i < N; i++) { |
