Relatively Prime Calculator

Check if two or more numbers are relatively prime (coprime), see Euclidean algorithm steps, prime factorizations, totient values, and coprimality grids.

GCD(a, b)
1
GCD(8, 15) via Euclidean algorithm
Relatively Prime?
✓ Yes — coprime
GCD = 1
LCM(a, b)
120
LCM = a × b (since coprime)
φ(a)
4
Euler's totient of 8: count of integers ≤ 8 coprime to it
φ(b)
8
Euler's totient of 15
Shared Prime Factors
None
No common primes → coprime

Euclidean Algorithm Steps

Stepabqr
115817
28711
37170

Prime Factorization Comparison

8

2^3

15

35

Red = shared prime (prevents coprimality). Green = unique prime.

Integers Coprime to 8 in [1, 50] (25 found)

135791113151719212325272931333537394143454749

Coprimality Grid (1–20)

1234567891011121314151617181920
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Green = coprime pair. Red = share common factor.

Planning notes, formulas, and examples

About the Relatively Prime Calculator

Two integers are **relatively prime** (also called **coprime** or **mutually prime**) when their greatest common divisor (GCD) equals 1 — meaning they share no prime factors. This concept is fundamental throughout number theory, cryptography, and algebra.

Coprime pairs appear everywhere in mathematics. In RSA encryption the public exponent must be coprime to Euler's totient of the modulus. In modular arithmetic, multiplicative inverses exist only when the base and modulus are coprime. Fractions are in lowest terms precisely when numerator and denominator are coprime. The Chinese Remainder Theorem requires pairwise-coprime moduli.

This calculator lets you enter two (or three) integers and see whether they are coprime, along with the full Euclidean-algorithm trace, prime-factorization comparison with shared primes highlighted, Euler's totient of each number, a full list of integers coprime to a within any range, and an interactive coprimality grid for visualising the pattern. Presets including both coprime and non-coprime pairs let you explore without typing.

When This Page Helps

Checking whether numbers are coprime is a core step in dozens of mathematical and computational contexts — from writing fractions in lowest terms to applying the Chinese Remainder Theorem. This calculator goes beyond a simple yes/no verdict: it shows the full Euclidean-algorithm trace, highlights shared prime factors, computes Euler's totient for each input, lists all coprimes within a range, and generates a colour-coded coprimality grid.

Students preparing for number-theory courses, competitive-math contests, or cryptography exams will find every intermediate value exposed and explained. Engineers working with modular arithmetic, hash designs, or random-number generators can quickly verify coprimality assumptions without coding a helper script.

How to Use the Inputs

  1. Enter the first integer a in the "Number a" field or click a preset pair.
  2. Enter the second integer b in the "Number b" field.
  3. Read the GCD and coprime verdict cards — GCD = 1 means coprime.
  4. Review the Euclidean algorithm step table for the full computation.
  5. Compare prime factorizations — red chips mark shared primes.
  6. Optionally enter a third number c to test pairwise coprimality.
  7. Adjust "List coprimes up to" to explore coprime counts in a range.
Formula used
Euclidean Algorithm: GCD(a, b) = GCD(b, a mod b) until remainder = 0. Two integers are relatively prime iff GCD(a, b) = 1. Euler's totient φ(n) counts integers in [1, n] coprime to n.

Example Calculation

Result: Coprime (GCD = 1)

8 = 2³ and 15 = 3 × 5 share no prime factors, so GCD(8, 15) = 1 and they are relatively prime. LCM(8, 15) = 120 = 8 × 15. φ(8) = 4, φ(15) = 8.

Tips & Best Practices

  • Click a preset pair to load both coprime and non-coprime examples.
  • Enter a third number c to test pairwise coprimality of three numbers simultaneously.
  • The coprimality grid reveals the diagonal symmetry and patterns (e.g., Farey sequences, Stern-Brocot).
  • If GCD ≠ 1, look at the red-highlighted shared primes to understand which factor prevents coprimality.
  • The list of coprimes to a corresponds to the totient function — its count equals φ(a).
  • Consecutive integers (n, n+1) are always coprime — verify this with any preset.

Coprimality in Number Theory

Coprime integers form the backbone of many classical results. Euler's totient function φ(n) counts integers less than n that are coprime to it, and Euler's theorem states that \(a^{\varphi(n)} \equiv 1 \pmod{n}\) when a and n are coprime. The Chinese Remainder Theorem (CRT) guarantees a unique solution to a system of simultaneous congruences when all moduli are pairwise coprime. Bézout's identity says that GCD(a, b) = 1 implies integers x, y exist with ax + by = 1 — the foundation for computing modular inverses.

Applications in Cryptography and Computing

RSA key generation selects primes p, q, computes n = pq and φ(n) = (p−1)(q−1), then picks a public exponent e coprime to φ(n). The Extended Euclidean Algorithm finds d ≡ e⁻¹ (mod φ(n)). Hash-table design often uses table sizes coprime to stepping increments to ensure full coverage. Linear congruential generators require the multiplier and modulus to be coprime for maximum period.

Coprimality Density and Open Questions

The probability that two random integers are coprime is 6/π² ≈ 61 %, a beautiful link between number theory and analysis. This density is visible in the coprimality grid, where roughly 61 % of cells are green. Open questions include efficient coprimality testing for extremely large multi-prime moduli and generalizations of Euler's totient to algebraic number fields.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • Two integers are relatively prime (coprime) when their greatest common divisor is 1 — they share no prime factors. Note that 1 is coprime to every integer.