Skip to content

Commit 71234c6

Browse files
committed
refactor: use references in gcdExtended
1 parent 259e0fc commit 71234c6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

math/ncr_modulo_p.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ namespace utils {
3333
* equation
3434
* @returns the gcd of a and b
3535
*/
36-
uint64_t gcdExtended(const uint64_t& a, const uint64_t& b, int64_t* x,
37-
int64_t* y) {
36+
uint64_t gcdExtended(const uint64_t& a, const uint64_t& b, int64_t& x,
37+
int64_t& y) {
3838
if (a == 0) {
39-
*x = 0, *y = 1;
39+
x = 0;
40+
y = 1;
4041
return b;
4142
}
4243

4344
int64_t x1 = 0, y1 = 0;
44-
uint64_t gcd = gcdExtended(b % a, a, &x1, &y1);
45+
uint64_t gcd = gcdExtended(b % a, a, x1, y1);
4546

46-
*x = y1 - (b / a) * x1;
47-
*y = x1;
47+
x = y1 - (b / a) * x1;
48+
y = x1;
4849
return gcd;
4950
}
5051

@@ -55,7 +56,7 @@ uint64_t gcdExtended(const uint64_t& a, const uint64_t& b, int64_t* x,
5556
*/
5657
int64_t modInverse(const uint64_t& a, const uint64_t& m) {
5758
int64_t x = 0, y = 0;
58-
uint64_t g = gcdExtended(a, m, &x, &y);
59+
uint64_t g = gcdExtended(a, m, x, y);
5960
if (g != 1) { // modular inverse doesn't exist
6061
return -1;
6162
} else {

0 commit comments

Comments
 (0)