Number theory & mathAnimated
GCD
The largest number that divides both inputs.
Time
O(log min(a, b))
Extra space
O(1)
Use it for
Simplifying fractions.
How it works
- The GCD is the largest number that divides both inputs without a remainder.
- Replace (a, b) by (b, a mod b) until b is 0.
- The remaining a is the GCD.
Watch it run
Loading animation…