// NUMBER THEORY · INTERMEDIATE
GCD & Euclidean AlgorithmDiscover the ancient algorithm that finds the greatest common divisor in seconds, and unlock the Extended GCD for cryptography and Diophantine equations.
Prerequisites: Basic division · Remainders · Prime numbers (optional)
// VISUALIZER
Watch remainders shrink the problem
The Euclidean algorithm is based on one powerful fact: GCD(a, b) = GCD(b, a mod b). Change a and b, press play, and see how each remainder becomes the new problem.
Press PLAY to watch the Euclidean algorithm step by step.
Current a
48
Current b
18
Remainder
?
Steps
0 / 4
// MINI GAME
Euclidean Racer
Beat the clock! Predict the remainder at each step of the Euclidean algorithm. Correct answers build your streak and score.
Loading race track...
// FLOWCHART
Algorithm flow
Press PLAY to trace the algorithm through the flowchart.
// PSEUDOCODE
Trace the code
Press PLAY to step through the algorithm line by line.
// TUTORIAL QUIZZES
Test your mastery
Progress from the basics of GCD to the Extended Euclidean Algorithm. Each quiz has 10 questions and awards XP.
// PRACTICE & ASSESS
Test your understanding
Now that you've learned the concept, put it into practice. Solve coding problems and take quizzes to reinforce what you've learned.
// REFERENCES
Sources & further reading
- [1]Euclid's Elements, Book VIIEuclid of Alexandria — Propositions 1–2 describe the algorithm
- [2]Introduction to Algorithms (CLRS)T. H. Cormen et al. — Number-theoretic algorithms and GCD
- [3]The Art of Computer Programming, Vol. 2Donald Knuth — Seminumerical Algorithms, Section 4.5.2
- [4]A Course in Number Theory and CryptographyNeal Koblitz — GCD and modular inverses
// READY?
Master the next number-theory skill
Now that you understand GCD, explore the Sieve of Eratosthenes, Prime Factorization, or the Chinese Remainder Theorem.