I want to find the inverse of $7 \bmod 18$. First of all i found that $gcd(7,18)=1$
Then i express the $gcd$ as a linear combination of $7$ and $18$ using Euclidian algorithm
$1=(-5)7+2(18)$
All good until now. However after that the textbook does this:
$1=(13-18)7 + 2(18)$
$1=(13)7+1(18)$
And this supposedly tell us that the inverse of $7 \bmod 18$ is $13$
Can someone explain the logic behind this? Also how come that $(13−18)7+2(18) = (13)7+1(18)$ ??