AlgoBazaAlgoBaza
Back to algorithms

Euclidean Algorithm (GCD)

The fastest way to get the GCD โ€” the greatest common divisor of two numbers. Instead of checking every divisor, we replace the pair (a, b) with (b, a % b) until b is zero.

Podstawowy
O(log min(a, b))O(1)OIJOILOGIA

๐Ÿฐ Euclidean Algorithm โ€” Games

Play both games to master the algorithm!

๐Ÿ’ก

Tip: Start with Game 1 โ€” cutting the cake shows where a // b and a % b come from and why the last square is the GCD. In Game 2 you run the code yourself: you compute the remainders and keep track of the pair (a, b), exactly like on paper in a contest.