summaryrefslogtreecommitdiff
path: root/content/math/lgsFp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'content/math/lgsFp.cpp')
-rw-r--r--content/math/lgsFp.cpp26
1 files changed, 13 insertions, 13 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