Skip to content

Commit 13580ea

Browse files
author
volimroze
committed
Fixed code style in Chinese Remainder Theorem
1 parent 00bdaa6 commit 13580ea

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/main/java/com/thealgorithms/maths/ChineseRemainderTheorem.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
package remainder;
22

3-
import java.util.*;
3+
import java.util.Arrays;
44

55
public class ChineseRemainderTheorem {
66

77
// Helper function to compute the greatest common divisor (GCD)
88
public static int gcd(int a, int b) {
9-
if (b == 0) return a;
9+
if (b == 0) {
10+
return a;
11+
}
1012
return gcd(b, a % b);
1113
}
1214

1315
// Helper function to compute the modular inverse of a modulo m
1416
// Uses the extended Euclidean algorithm
1517
public static int modInverse(int a, int m) {
16-
int m0 = m, t, q;
17-
int x0 = 0, x1 = 1;
18-
19-
if (m == 1) return 0;
18+
int m0 = m;
19+
int t;
20+
int q;
21+
int x0 = 0;
22+
int x1 = 1;
23+
24+
if (m == 1) {
25+
return 0;
26+
}
2027

2128
while (a > 1) {
2229
// q is quotient
@@ -33,7 +40,9 @@ public static int modInverse(int a, int m) {
3340
}
3441

3542
// Make x1 positive
36-
if (x1 < 0) x1 += m0;
43+
if (x1 < 0) {
44+
x1 += m0;
45+
}
3746

3847
return x1;
3948
}
@@ -43,7 +52,9 @@ public static int modInverse(int a, int m) {
4352
public static int findMinX(int[] num, int[] rem, int k) {
4453
// Compute product of all numbers
4554
int prod = 1;
46-
for (int i = 0; i < k; i++) prod *= num[i];
55+
for (int i = 0; i < k; i++) {
56+
prod *= num[i];
57+
}
4758

4859
// Initialize result
4960
int result = 0;

0 commit comments

Comments
 (0)