Roboculator
Online CalculatorsCategoriesDate & EventsNews
Get Started
Online CalculatorsCategoriesDate & EventsNewsGet Started
Roboculator

Smart calculators for every challenge. Free, fast, and private.

Categories

  • Finance
  • Health
  • Math
  • Construction
  • Conversion
  • Everyday Life

Popular Tools

  • Date & Events
  • Loan Calculator
  • BMI Calculator
  • Percentage Calc
  • Latest News
  • Search All

Resources

  • Glossary
  • Topic Tags
  • News & Insights

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Service
  • Editorial Policy
  • Disclaimer
© 2026 Roboculator. All rights reserved.
Roboculator

roboculator.com

  1. Home
  2. /Math
  3. /Number Theory Calculators
  4. /Euclid's Algorithm Calculator

Euclid's Algorithm Calculator

Last updated: March 16, 2026

Calculator

Results

Greatest Common Divisor

21

Least Common Multiple

1,260

Coprime Flag

0

1=yes, 0=no

Number of Common Factors

2

Fraction Reduction Factor

21

Reduced First Integer

12

Reduced Second Integer

5

Euclidean Steps Used

3

Step 1 Dividend

252

Step 1 Divisor

105

Step 1 Quotient

2

Step 1 Remainder

42

Step 2 Dividend

105

Step 2 Divisor

42

Step 2 Quotient

2

Step 2 Remainder

21

Step 3 Dividend

42

Step 3 Divisor

21

Step 3 Quotient

2

Step 3 Remainder

0

Step 4 Dividend

0

Step 4 Divisor

0

Step 4 Quotient

0

Step 4 Remainder

0

Step 5 Dividend

0

Step 5 Divisor

0

Step 5 Quotient

0

Step 5 Remainder

0

Step 6 Dividend

0

Step 6 Divisor

0

Step 6 Quotient

0

Step 6 Remainder

0

Results

Greatest Common Divisor

21

Least Common Multiple

1,260

Coprime Flag

0

1=yes, 0=no

Number of Common Factors

2

Fraction Reduction Factor

21

Reduced First Integer

12

Reduced Second Integer

5

Euclidean Steps Used

3

Step 1 Dividend

252

Step 1 Divisor

105

Step 1 Quotient

2

Step 1 Remainder

42

Step 2 Dividend

105

Step 2 Divisor

42

Step 2 Quotient

2

Step 2 Remainder

21

Step 3 Dividend

42

Step 3 Divisor

21

Step 3 Quotient

2

Step 3 Remainder

0

Step 4 Dividend

0

Step 4 Divisor

0

Step 4 Quotient

0

Step 4 Remainder

0

Step 5 Dividend

0

Step 5 Divisor

0

Step 5 Quotient

0

Step 5 Remainder

0

Step 6 Dividend

0

Step 6 Divisor

0

Step 6 Quotient

0

Step 6 Remainder

0

Euclid's Algorithm is one of the oldest and most elegant algorithms in mathematics, dating back to around 300 BCE in Euclid's Elements (Book VII, Propositions 1-2). It computes the Greatest Common Factor (GCF) of two integers through a sequence of divisions, where each step replaces the larger number with the remainder of dividing the two.

The algorithm is based on the fundamental identity:

$$\text{GCF}(a, b) = \text{GCF}(b, a \bmod b)$$

This works because any common divisor of $$a$$ and $$b$$ must also divide $$a - qb = r$$ (the remainder), and vice versa. By repeatedly applying this reduction, the numbers shrink until the remainder reaches zero, at which point the last nonzero remainder is the GCF.

Our calculator displays every step of the algorithm — the dividend, divisor, quotient, and remainder — so you can trace the entire computation. This step-by-step visibility makes it an invaluable learning tool for students studying number theory, and a practical verification tool for professionals working with modular arithmetic, cryptographic key generation, or Diophantine equations.

The algorithm's efficiency is remarkable: it requires at most $$2\log_2(\min(a,b))$$ steps, making it $$O(\log n)$$ — far superior to brute-force factor enumeration. The worst case occurs with consecutive Fibonacci numbers, which produce quotients of 1 at every step, maximizing the number of iterations.

Visual Analysis

How It Works

The algorithm proceeds as follows:

Step 1: Divide the larger number by the smaller: $$a = b \cdot q_1 + r_1$$

Step 2: If $$r_1 = 0$$, then $$\text{GCF} = b$$. Otherwise, replace: $$b = r_1 \cdot q_2 + r_2$$

Step 3: Continue: $$r_1 = r_2 \cdot q_3 + r_3$$

Repeat until some $$r_k = 0$$. Then $$\text{GCF} = r_{k-1}$$ (the last nonzero remainder).

For example, $$\text{GCF}(252, 105)$$:

$$252 = 105 \times 2 + 42$$

$$105 = 42 \times 2 + 21$$

$$42 = 21 \times 2 + 0$$

So $$\text{GCF}(252, 105) = 21$$ in 3 steps.

The sequence of quotients $$[q_1, q_2, \ldots, q_k]$$ forms the continued fraction representation of $$a/b$$, connecting this algorithm to deep results in Diophantine approximation.

Understanding Your Results

The step count reveals the computational complexity for your specific inputs. Fewer steps mean the numbers share a large common factor discovered quickly. The maximum steps for numbers below $$n$$ occurs with consecutive Fibonacci numbers (e.g., 89 and 55 require 9 steps). If the GCF equals 1, the numbers are coprime. The quotient sequence provides the continued fraction expansion of $$a/b$$, useful in rational approximation theory.

Worked Examples

GCF of 252 and 105

Inputs

a252
b105

Results

gcf21
lcm1260
steps used3
s1 q2
s1 r42
s2 q2
s2 r21
s3 q2
s3 r0

252 = 2×105 + 42, then 105 = 2×42 + 21, then 42 = 2×21 + 0. GCF = 21 in 3 steps.

GCF of 89 and 55 (Fibonacci — worst case)

Inputs

a89
b55

Results

gcf1
lcm4895
steps used9
s1 q1
s1 r34
s2 q1
s2 r21
coprime1

Consecutive Fibonacci numbers are coprime and require the maximum steps. All quotients are 1.

Frequently Asked Questions

It appears in Euclid's Elements (c. 300 BCE), Book VII, Propositions 1-2, making it one of the oldest known algorithms — over 2,300 years old. While the method was likely known before Euclid, his systematic presentation in the Elements established it as a foundational algorithm in mathematics.

The algorithm takes at most $$2\log_2(\min(a,b))$$ steps. Gabriel Lame proved in 1844 that the number of steps never exceeds 5 times the number of digits in the smaller number. The worst case occurs with consecutive Fibonacci numbers, where every quotient equals 1.

The Extended Euclidean Algorithm not only finds $$\text{GCF}(a,b)$$ but also integers $$x, y$$ such that $$ax + by = \text{GCF}(a,b)$$ (Bezout's identity). This is essential for computing modular inverses in cryptography, solving linear Diophantine equations, and RSA key generation.

Fibonacci numbers $$F_n$$ and $$F_{n-1}$$ produce quotient 1 at every step: $$F_n = 1 \cdot F_{n-1} + F_{n-2}$$. This means the remainders decrease as slowly as possible (each is barely less than the divisor), maximizing iterations. Lame's theorem uses this fact to bound the algorithm's complexity.

In RSA encryption, you need the modular inverse of $$e$$ modulo $$\phi(n)$$, computed via the Extended Euclidean Algorithm. The algorithm also verifies that $$\text{GCF}(e, \phi(n)) = 1$$ (required for a valid public key). It runs in the key generation phase of RSA, Diffie-Hellman, and elliptic curve cryptosystems.

Yes. The algorithm generalizes to any Euclidean domain, including polynomials. For polynomials, division with remainder replaces integer division, and the algorithm finds the greatest common divisor polynomial. This is used in symbolic algebra, coding theory, and control systems engineering.

Sources & Methodology

Euclid — Elements, Book VII (c. 300 BCE); Knuth, D. E. — The Art of Computer Programming, Vol. 2: Seminumerical Algorithms (3rd ed., 1997); Lame, G. — Note sur la limite du nombre des divisions dans la recherche du plus grand commun diviseur (1844); Cormen, T. et al. — Introduction to Algorithms (4th ed., MIT Press, 2022)
R

Roboculator Team

The Roboculator Team explains calculations, planning tools, and practical formulas in clear language for real-life situations.

How helpful was this calculator?

Be the first to rate!

Related Calculators

Prime Number Calculator

Number Theory Calculators

Prime Factorization Calculator

Number Theory Calculators

GCF Calculator

Number Theory Calculators

LCM Calculator

Number Theory Calculators

Factor Calculator

Number Theory Calculators

Common Factor Calculator

Number Theory Calculators