Math

Problem shape

Beginner
4
8
15
16
23
42
Core idea

Repeatedly replace the larger number with its remainder.

Step 1 / 5
Problem shape
Current lesson

Euclidean GCD Lab

Math Beginner

Euclidean GCD

Welcome to the Euclidean GCD algorithm lab. Repeatedly replace the larger number with its remainder. Use it when: Use for divisibility, fractions, modular math, and number theory basics. The time complexity is O(log min(a, b)), and the space complexity is O(1). The pseudocode is: while b != 0 temp = a % b a = b b = temp return a As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(log min(a, b))

Space

O(1)

Pseudocode

while b != 0
  temp = a % b
  a = b
  b = temp
return a
Open deeper structure lesson
1.0x