From aca95353f22fb48fab74bf45de85f8badaa2e274 Mon Sep 17 00:00:00 2001 From: Yidi Date: Fri, 6 Jun 2025 15:21:51 +0200 Subject: improve gauss + fix latex --- content/math/lgsFp.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'content/math/lgsFp.cpp') 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 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 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 -- cgit v1.2.3