From f86e01c8e4b1ef9725e0be102cf573d1359080e3 Mon Sep 17 00:00:00 2001 From: Ariel Date: Mon, 19 Feb 2024 16:53:47 +0800 Subject: [PATCH] Update exgcd.cc --- number/exgcd.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/number/exgcd.cc b/number/exgcd.cc index c1d276d..fdda090 100644 --- a/number/exgcd.cc +++ b/number/exgcd.cc @@ -50,6 +50,10 @@ 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) { + if (b != 0) return nullopt; + return 0; + } if (a < 0 && a != LLONG_MIN && b != LLONG_MIN) a = -a, b = -b; auto sol = diophantine(a, n, b); if (sol == nullopt) {