Today as I am revising about the extended euclidean algorithm, and I stumble a code library that does this:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll euclid(ll a, ll b, ll &x, ll &y) {
if (!b) {
return x = 1, y = 0, a;
}
ll d = euclid(b, a % b, y, x);
return y -= a / b * x, d;
}
I am curious that the return type is a long long
, and from my initial search, in a multiple comma return in c++, only the right value is kept and returned. So the question is, why does the author of this function still want to x = 1, y = 0
or y -= a / b * x
on the left hand side of the same return line?