diff --git a/algorithms/graph/kruskal.cpp b/algorithms/graph/kruskal.cpp index 6963eb263b8005016d1ff3b09ed4ba60e0eba4e5..15218e7feb68f422a665e0b2ac852c77f050d4eb 100644 --- a/algorithms/graph/kruskal.cpp +++ b/algorithms/graph/kruskal.cpp @@ -28,9 +28,6 @@ struct Kruskal { }); int size = 0; - for (int i = 0; i < N; i++) - ds.make_set(i); - for (int i = 0; i < edges.size(); i++) { int pu = ds.find_set(edges[i].fi.fi); int pv = ds.find_set(edges[i].fi.se); diff --git a/algorithms/math/big_integer.cpp b/algorithms/math/big_integer.cpp index cb0b862825760af5af4f32479e4f894a40817838..28851c8649c7349dcda5043b4f13b1862f4e1cbe 100644 --- a/algorithms/math/big_integer.cpp +++ b/algorithms/math/big_integer.cpp @@ -50,7 +50,7 @@ struct BigInt { return ans; } - /// Remove leading zeros. + // Removes leading zeros. void trim() { while (!num.empty() && num.back() == 0) num.pop_back(); @@ -83,21 +83,21 @@ struct BigInt { bool operator!=(const BigInt &x) const { return !(*this == x); } - /// Handles -x (change of sign). + // Handles -x (change of sign). BigInt operator-() const { BigInt ans = *this; ans.sign = -sign; return ans; } - /// Returs absolute value. + // Returs absolute value. BigInt abs() const { BigInt ans = *this; ans.sign *= ans.sign; return ans; } - /// Transforms string into BigInt. + // Transforms string into BigInt. void read(const string &s) { sign = 1; num.clear(); @@ -139,7 +139,7 @@ struct BigInt { return stream; } - /// Handles vector operations. + // Handles vector operations. int back() const { return num.back(); } bool empty() const { return num.empty(); } size_t size() const { return num.size(); } diff --git a/algorithms/math/modular_multiplicative_inverse.cpp b/algorithms/math/modular_multiplicative_inverse.cpp index 5432807bd0de69ddb7fa1dedbbacb8e6d9b7c3b3..97a7dcc9331c32eecc608a57b8454f89793820de 100644 --- a/algorithms/math/modular_multiplicative_inverse.cpp +++ b/algorithms/math/modular_multiplicative_inverse.cpp @@ -3,20 +3,20 @@ /// Time: O(log m) /// Space: O(1) -// ============= Fermat's Little Theorem ============ -// Used when m is prime +struct ModMultInv { -int mod_inverse(int a, int m) { - BinaryExponentiation bin_exp; - return bin_exp.run(a, m - 2); -} + // Fermat's Little Theorem: Used when m is prime + int fermat(int a, int m) { + BinaryExponentiation bin_exp; + return bin_exp.run(a, m - 2); + } -// ========== Extended Euclidean Algorithm ========== -// Used when m and a are coprime - -int mod_inverse(int a, int m) { - ExtendedEuclidean ext_gcd; - int x, y; - int g = ext_gcd.run(a, m, x, y); - return (x % m + m) % m; -} + // Extended Euclidean Algorithm: Used when m + // and a are coprime + int extended_euclidean(int a, int m) { + ExtendedEuclidean ext_gcd; + int x, y; + int g = ext_gcd.run(a, m, x, y); + return (x % m + m) % m; + } +}; diff --git a/caderno.pdf b/caderno.pdf index ec51993b8af67878947811daeb57ae4959d95f1e..05adf703638921726f8fe8b69b23750388d1f202 100644 Binary files a/caderno.pdf and b/caderno.pdf differ