Understanding the greatest common factor
Two numbers usually share more than you would guess. Take 12 and 18: both divide by 1, 2, 3 and 6, so their common factors are 1, 2, 3 and 6, and the greatest of them — the greatest common factor — is 6. That single number is surprisingly useful.
Formula and method
The last non-zero remainder is the greatest common divisor. a, b — the two entered whole numbers. a mod b — the remainder when a is divided by b. The last non-zero remainder — the greatest common factor. How it works, for 12 and 18. Start with the pair (18, 12): 18 ÷ 12 = 1 remainder 6, so the pair becomes (12, 6). Then 12 ÷ 6 = 2 remainder 0, so the process stops, and the last non-zero remainder, 6, is the answer. The reason it works is that any number dividing both members of a pair also divides their remainder, so the set of common divisors never changes as the pair shrinks — it only gets smaller, until the remainder is zero and the smaller number is the greatest common divisor. The method needs no factor lists and no prime factorisation, and it stays fast even for large numbers, because each step at least halves the larger number. It also handles the order either way: entering 18 then 12 gives the same answer as 12 then 18. The result is always a positive whole number, and it is never larger than the smaller of the two inputs.
Worked example
Example 1 — 12 and 18 (the live-page example) The two numbers are 12 and 18. Factors of 12: 1, 2, 3, 4, 6, 12 Factors of 18: 1, 2, 3, 6, 9, 18 Common factors: 1, 2, 3, 6 — the greatest is 6 Euclidean check: 18 ÷ 12 = 1 remainder 6; 12 ÷ 6 = 2 remainder 0, so the last non-zero remainder is 6 The greatest common factor is 6. Both numbers divide by 6 with nothing left: 12 ÷ 6 = 2 and 18 ÷ 6 = 3, which is why the fraction 12/18 reduces to 2/3 and the ratio 12:18 simplifies to 2:3. No larger whole number divides both — 12 itself divides 12 but not 18, and 9 divides 18 but not 12.