diff --git a/number/exgcd.cc b/number/exgcd.cc index 7a02a14..c1d276d 100644 --- a/number/exgcd.cc +++ b/number/exgcd.cc @@ -50,6 +50,7 @@ namespace Exgcd { // find the minimal non-negative integral solution of `ax = b (mod n)` optional congruential(ll a, ll b, ll n) { + if (a < 0 && a != LLONG_MIN && b != LLONG_MIN) a = -a, b = -b; auto sol = diophantine(a, n, b); if (sol == nullopt) { return nullopt;