Toolkit 79

Computing gcd(a,b)

Useful Properties

gcd(a,a)=a\gcd(a,a)=|a|
gcd(a+kb,b)=gcd(a,b)\gcd(a+kb,b)=\gcd(a,b)
gcd(a,b)=gcd(amodb,b)\gcd(a,b)=\gcd(a\bmod b,b)

Use divisibility to simplify the numbers before applying the Euclidean algorithm whenever possible.


Example

Let gcd(2n+3,5n4)=d\gcd(2n+3,\,5n-4)=d.

Since d(2n+3)d\mid(2n+3), multiply by 55 to obtain d(10n+15)d\mid(10n+15).

Since d(5n4)d\mid(5n-4), multiply by 22 to obtain d(10n8)d\mid(10n-8).

Subtracting gives d23d\mid23, so the only possibilities are d=1d=1 or d=23d=23.

Finally, verify that each possible value is attainable by finding an appropriate value of nn.

Examples: n=1: gcd(5,1)=1,n=10: gcd(23,46)=23.n=1:\ \gcd(5,1)=1,\qquad n=10:\ \gcd(23,46)=23.