Math Fundamentals18 sections · 814 units
Open in Course

Naive GCD Method

Listing all divisors

You can find gcd(a, b) by listing divisors of both numbers and picking the largest common one. Check every number from 1 to min(a, b).

For gcd(48, 18): check 1, 2, 3... up to 18. Numbers that divide both 48 and 18 are 1, 2, 3, 6. The largest is 6.

This works but takes O(min(a, b)) time. If a = 10^9, you check a billion numbers. Too slow.