summaryrefslogtreecommitdiff
path: root/math/extendedEuclid.cpp
diff options
context:
space:
mode:
authorYidi <noob999noob999@gmail.com>2024-03-22 12:21:09 +0100
committerYidi <noob999noob999@gmail.com>2024-03-22 12:21:09 +0100
commit0a1fd7ed34e3a15f6ac3f646d30c9f0b6db5d3ed (patch)
tree928daca83d5a6ab4c63198dd855d180ee21a7e10 /math/extendedEuclid.cpp
parentdbcd02da96922c2a667ec16e390ef8263580a66c (diff)
change extended euclid
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};
}