From 3f1252be74bcbc03a4ba890cd2088b96210a71a3 Mon Sep 17 00:00:00 2001 From: Alexander Molnar <37451552+BTmathic@users.noreply.github.com> Date: Tue, 20 Nov 2018 00:59:32 -0500 Subject: [PATCH] Added content to stub (#34377) * Added content to stub Gave definition, examples, two methods to compute as well as a JavaScript algorithm, and some generalizations. * Removed content Removed external links and added internal links to FCC guide pages when possible. --- .../greatest-common-factor/index.md | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/guide/english/mathematics/greatest-common-factor/index.md b/guide/english/mathematics/greatest-common-factor/index.md index ad1e3fce08..627f24f0bf 100644 --- a/guide/english/mathematics/greatest-common-factor/index.md +++ b/guide/english/mathematics/greatest-common-factor/index.md @@ -3,13 +3,48 @@ title: Greatest Common Factor --- ## Greatest Common Factor -This is a stub. Help our community expand it. +The greatest common factor (or more appropriately the great common divisor, otherwise known as the highest common factor, greatest common measure or highest common divisor) of two integers -- not both 0 -- is the largest positive integer that divides each of the integers. For short, we write the greatest common divisor of a and b as gcd(a,b). -This quick style guide will help ensure your pull request gets accepted. +For example, the gcd of 15 and 6 is 3, while the gcd of -42 and 6 is 6. We also have gcd(2,3) = 1 and gcd(17,0) = 17. There are two convensions for gcd(0,0). Either it is not defined to avoid needing special cases, or equal to 0. - +There are many ways to compute the gcd of two integers, we will cover two simple algorithms here. Firstly, to see why it can also be called the greatest common factor, using the Fundamental Theorem of Arithmetic, every positive integer factors uniquely (up to order) into prime factors, so we can simply compare prime factorizations of two integers to see all the common factors. -#### More Information: - +For example, if we want to find the gcd of 3600 and 2640, we note that +
3600 = 2 × 2 × 2 × 2 × 3 × 3 × 5 × 5 = 24 × 32 × 52,
+ 2640 = 2 × 2 × 2 × 2 × 3 × 5 × 11 = 24 × 3 × 5 × 11.
a = bq1 + r1,
+ +we have r1 = a - bq1, so any common factor of a and b divides the right hand side, i.e., r1 as well. Continuing with this, dividing b by r1 we get a quotient of q2 = 2 and a remainder of r2 = 720, with b = q2r1 + r2. + +Dividing r1 by r2, gives q3 = 1 and r3 = 240, and finally we have r3 divides r2 evenly (i.e., r4 = 0) with a quotient q4 = 3. So, putting everything together we have + +a = b + r1,
+ b = 2r1 + r2,
+ r1 = r2 + r3,
+ r2 = 3r3