Find GCD using Euclidean Algorithm

published on 25, Tháng 8, 2025, 15:57

Hello! This is a tutorial on how to calculate the GCD (greatest common divisor) of two numbers without using import math. I'm using the Euclidean algorithm—basic knowledge but powerful for competitive coding.


For starters, the GCD, or greatest common divisor of a and b is the greatest number that both a and b is divisible to. The idea of this algorithm is that GCD(a, b) = GCD(b, a % b). When b is 0, the GCD is a. So the the code is like this:

  1. If b equals 0: print a
  2. Else: just use recursion. Return GCD(b, a % b)

Interactive Code Editor

No Scratch Image Available

The tutorial author has not uploaded a Scratch image yet.