1

I've come up with this question in a programming book, and couldn't figure it out :

Given four positive integers $a, b, c$ and $d$, explain what value is computed by $\gcd(\gcd(a, b), \gcd(c, d))$.

Fermat
  • 5,366

2 Answers2

2

Your title give the answer: the expression gives the greatest common divisor of all four of the integers $a,b,c,$ and $d$.

This is the largest integer that divides all four of the numbers. Such a number exists since $1$ divides all four numbers and anything larger than the maximum of the four numbers will not divide any of them.

Rory Daulton
  • 32,888
  • 6
  • 47
  • 64
1

Let $g=\gcd(\gcd(a, b), \gcd(c, d))$. Then by the definition $g\mid \gcd(a, b)$ and since $\gcd(a, b)\mid a, \gcd(a, b)\mid b$ therefore $g\mid a$ and $g\mid b$. similarly $g\mid c$ and $g\mid d$. So g is a common divisor of these four integers. To see why $g$ is the greatest common divisor of these integers, assume that $f$ is any common divisor of $a,b,c$ and $d$. Then $f\mid a$ and $f\mid b$ and hence $f\mid \gcd(a, b)$ and indeed, $f\mid \gcd(c, d)$. So $f$ must divide $\gcd(\gcd(a, b), \gcd(c, d))$ or $f\mid g$. By the definition, $g$ is the greatest common divisor of $a,b,c$ and $d$.

Fermat
  • 5,366