Skip to content
Snippets Groups Projects
Commit b328e501 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Small fixes

parent b9f0e47b
No related branches found
No related tags found
No related merge requests found
...@@ -28,9 +28,6 @@ struct Kruskal { ...@@ -28,9 +28,6 @@ struct Kruskal {
}); });
int size = 0; int size = 0;
for (int i = 0; i < N; i++)
ds.make_set(i);
for (int i = 0; i < edges.size(); i++) { for (int i = 0; i < edges.size(); i++) {
int pu = ds.find_set(edges[i].fi.fi); int pu = ds.find_set(edges[i].fi.fi);
int pv = ds.find_set(edges[i].fi.se); int pv = ds.find_set(edges[i].fi.se);
......
...@@ -50,7 +50,7 @@ struct BigInt { ...@@ -50,7 +50,7 @@ struct BigInt {
return ans; return ans;
} }
/// Remove leading zeros. // Removes leading zeros.
void trim() { void trim() {
while (!num.empty() && num.back() == 0) while (!num.empty() && num.back() == 0)
num.pop_back(); num.pop_back();
...@@ -83,21 +83,21 @@ struct BigInt { ...@@ -83,21 +83,21 @@ struct BigInt {
bool operator!=(const BigInt &x) const { return !(*this == x); } bool operator!=(const BigInt &x) const { return !(*this == x); }
/// Handles -x (change of sign). // Handles -x (change of sign).
BigInt operator-() const { BigInt operator-() const {
BigInt ans = *this; BigInt ans = *this;
ans.sign = -sign; ans.sign = -sign;
return ans; return ans;
} }
/// Returs absolute value. // Returs absolute value.
BigInt abs() const { BigInt abs() const {
BigInt ans = *this; BigInt ans = *this;
ans.sign *= ans.sign; ans.sign *= ans.sign;
return ans; return ans;
} }
/// Transforms string into BigInt. // Transforms string into BigInt.
void read(const string &s) { void read(const string &s) {
sign = 1; sign = 1;
num.clear(); num.clear();
...@@ -139,7 +139,7 @@ struct BigInt { ...@@ -139,7 +139,7 @@ struct BigInt {
return stream; return stream;
} }
/// Handles vector operations. // Handles vector operations.
int back() const { return num.back(); } int back() const { return num.back(); }
bool empty() const { return num.empty(); } bool empty() const { return num.empty(); }
size_t size() const { return num.size(); } size_t size() const { return num.size(); }
......
...@@ -3,20 +3,20 @@ ...@@ -3,20 +3,20 @@
/// Time: O(log m) /// Time: O(log m)
/// Space: O(1) /// Space: O(1)
// ============= Fermat's Little Theorem ============ struct ModMultInv {
// Used when m is prime
int mod_inverse(int a, int m) { // Fermat's Little Theorem: Used when m is prime
BinaryExponentiation bin_exp; int fermat(int a, int m) {
return bin_exp.run(a, m - 2); BinaryExponentiation bin_exp;
} return bin_exp.run(a, m - 2);
}
// ========== Extended Euclidean Algorithm ========== // Extended Euclidean Algorithm: Used when m
// Used when m and a are coprime // and a are coprime
int extended_euclidean(int a, int m) {
int mod_inverse(int a, int m) { ExtendedEuclidean ext_gcd;
ExtendedEuclidean ext_gcd; int x, y;
int x, y; int g = ext_gcd.run(a, m, x, y);
int g = ext_gcd.run(a, m, x, y); return (x % m + m) % m;
return (x % m + m) % m; }
} };
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment