Given a mod b and find its inverse, then doing the extended GCD.
ax + by = gcd(a,b)
After I get x and y, how do I get its inverse?
If gcd(a,b) != 1
, a
does not have an inverse mod b
.
Otherwise ax + by = 1
, which means that ax = 1 (mod b)
, so x
is the inverse of a
mod b
.