1
0
Fork 0

Update exgcd.cc

This commit is contained in:
Ariel 2024-02-19 16:53:47 +08:00 committed by GitHub
parent 70f5673363
commit f86e01c8e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -50,6 +50,10 @@ namespace Exgcd {
// find the minimal non-negative integral solution of `ax = b (mod n)`
optional<ll> 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) {