summaryrefslogtreecommitdiff
path: root/math/extendedEuclid.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-04-01 19:59:01 +0200
committerGloria Mundi <gloria@gloria-mundi.eu>2024-04-01 19:59:01 +0200
commit33343f96d94f2d7f12567b1c227e4e2399c8bd1b (patch)
tree16b5ef80ee4605ce88410911fbb6beb6dfc1d7b2 /math/extendedEuclid.cpp
parent4fc39dcd54243609febc1ce4c8a1470b3d31fd47 (diff)
parent98aa28427350e72cb9abe4071c0c6b6870b7e6cc (diff)
merge mzuenni changes
Diffstat (limited to 'math/extendedEuclid.cpp')
-rw-r--r--math/extendedEuclid.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/math/extendedEuclid.cpp b/math/extendedEuclid.cpp
index d016a63..ecf4a16 100644
--- a/math/extendedEuclid.cpp
+++ b/math/extendedEuclid.cpp
@@ -1,7 +1,6 @@
// a*x + b*y = ggt(a, b)
-ll extendedEuclid(ll a, ll b, ll& x, ll& y) {
- if (a == 0) {x = 0; y = 1; return b;}
- ll x1, y1, d = extendedEuclid(b % a, a, x1, y1);
- x = y1 - (b / a) * x1; y = x1;
- return d;
+array<ll, 3> extendedEuclid(ll a, ll b) {
+ if (a == 0) return {b, 0, 1};
+ auto [d, x, y] = extendedEuclid(b % a, a);
+ return {d, y - (b / a) * x, x};
}