From c0475c4997dcd3f601cf00073563e99d943c6d35 Mon Sep 17 00:00:00 2001 From: Alejandro Mcewen Date: Thu, 11 Sep 2025 16:24:58 -0500 Subject: [PATCH 1/2] Agregando comentario de gauss jordan --- code/math/gaussjordan_modular.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/math/gaussjordan_modular.cpp b/code/math/gaussjordan_modular.cpp index 0c8602b..67105a1 100644 --- a/code/math/gaussjordan_modular.cpp +++ b/code/math/gaussjordan_modular.cpp @@ -1,6 +1,6 @@ const int eps = 0, mod = 1e9+7; -int gauss(vector &a, vi &ans) { +int gauss(vector &a, vi &ans) { // a matrix n, m + 1 donde la ultima columna es b int n = sz(a), m = sz(a[0]) - 1; vi where(m, -1); for(int col=0, row=0; col Date: Thu, 11 Sep 2025 16:38:46 -0500 Subject: [PATCH 2/2] Done with changes --- code/math/gaussjordan.cpp | 9 +++++---- code/math/gaussjordan_modular.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/code/math/gaussjordan.cpp b/code/math/gaussjordan.cpp index 48ad56f..a74819f 100644 --- a/code/math/gaussjordan.cpp +++ b/code/math/gaussjordan.cpp @@ -1,4 +1,5 @@ -int gauss(vector> &a, vector &ans) { +// a := matriz n x (m+1) , la ultima columna es b, en el sistema Ax = b +int gauss(vector> &a, vector &x) { int n = sz(a), m = sz(a[0]) - 1; vi where(m, -1); for(int col=0, row=0; col> &a, vector &ans) { ++row; } - ans.assign(m, 0); + x.assign(m, 0); forn(i,m){ - if(where[i] != -1) ans[i] = a[where[i]][m] / a[where[i]][i]; + if(where[i] != -1) x[i] = a[where[i]][m] / a[where[i]][i]; } forn(i,n){ double sum = 0; - forn(j,m) sum += ans[j] * a[i][j]; + forn(j,m) sum += x[j] * a[i][j]; if(abs(sum - a[i][m]) > eps) return 0; } diff --git a/code/math/gaussjordan_modular.cpp b/code/math/gaussjordan_modular.cpp index 67105a1..8832b13 100644 --- a/code/math/gaussjordan_modular.cpp +++ b/code/math/gaussjordan_modular.cpp @@ -1,6 +1,6 @@ const int eps = 0, mod = 1e9+7; - -int gauss(vector &a, vi &ans) { // a matrix n, m + 1 donde la ultima columna es b +// a := matriz n x (m+1) , la ultima columna es b, en el sistema Ax = b +int gauss(vector &a, vi &x) { int n = sz(a), m = sz(a[0]) - 1; vi where(m, -1); for(int col=0, row=0; col &a, vi &ans) { // a matrix n, m + 1 donde la ultima columna ++row; } - ans.assign(m, 0); + x.assign(m, 0); forn(i,m){ - if(where[i] != -1) ans[i] = 1LL*a[where[i]][m] * inv(a[where[i]][i])%mod; + if(where[i] != -1) x[i] = 1LL*a[where[i]][m] * inv(a[where[i]][i])%mod; } forn(i,n){ ll sum = 0; - forn(j,m) sum = (sum + 1LL*ans[j] * a[i][j])%mod; + forn(j,m) sum = (sum + 1LL*x[j] * a[i][j])%mod; if(abs(sum - a[i][m]) > eps) return 0; }