Three routes lead to the same destination, each preferable in different situations. Listing factors is transparent for small numbers but quickly impractical; prime factorization is efficient when factor structures are accessible; the Euclidean algorithm avoids factoring entirely and stays fast even for very large numbers. The table below collects all three side by side — the kind of inputs each handles best, the mechanics in one line, and a worked example.
| Method |
Best for |
How it works |
Worked example |
| Listing factors |
small inputs; transparent for teaching |
list all factors of each number, intersect the lists, take the largest |
gcd(24, 36): factors of 24 = {1,2,3,4,6,8,12,24}, factors of 36 = {1,2,3,4,6,9,12,18,36} → common = {1,2,3,4,6,12} → 12 |
| Prime factorization |
factorizations are easy to obtain or already known |
factor both numbers; for each prime, take the minimum exponent appearing in either factorization |
gcd(48, 180): 48 = 2⁴ · 3, 180 = 2² · 3² · 5 → 2² · 3 = 12 |
| Euclidean algorithm |
large numbers; factorization difficult; most efficient overall |
repeatedly replace (a, b) with (b, a mod b) — using the modulo operation — until b = 0; the final nonzero a is the gcd |
gcd(252, 105): 252 = 105·2 + 42, 105 = 42·2 + 21, 42 = 21·2 + 0 → 21 |