Skip to main content

Relatively Prime Calculator

Solve relatively prime problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.

Share this calculator

Formula

Two numbers a and b are relatively prime if GCD(a, b) = 1

The greatest common divisor (GCD) is computed using the Euclidean algorithm. If the GCD equals 1, the numbers share no common prime factors and are called relatively prime, coprime, or mutually prime. The LCM is calculated as (a x b) / GCD(a, b).

Worked Examples

Example 1: Checking if 15 and 28 are Relatively Prime

Problem: Determine whether 15 and 28 are relatively prime and find their GCD.

Solution: Prime factors of 15: 3, 5\nPrime factors of 28: 2, 2, 7\nNo common prime factors exist.\nEuclidean algorithm: GCD(28, 15) -> 28 = 1 x 15 + 13 -> 15 = 1 x 13 + 2 -> 13 = 6 x 2 + 1 -> 2 = 2 x 1 + 0\nGCD = 1

Result: 15 and 28 ARE relatively prime (GCD = 1), LCM = 420

Example 2: Checking if 24 and 36 are Relatively Prime

Problem: Determine whether 24 and 36 are relatively prime.

Solution: Prime factors of 24: 2, 2, 2, 3\nPrime factors of 36: 2, 2, 3, 3\nCommon prime factors: 2, 2, 3 -> GCD = 12\nEuclidean algorithm: GCD(36, 24) -> 36 = 1 x 24 + 12 -> 24 = 2 x 12 + 0\nGCD = 12, not 1.

Result: 24 and 36 are NOT relatively prime (GCD = 12). Reduced coprime form: 2 and 3.

Frequently Asked Questions

What does it mean for two numbers to be relatively prime?

Two numbers are relatively prime (also called coprime or mutually prime) when their greatest common divisor (GCD) is exactly 1, meaning they share no common factors other than 1. For example, 8 and 15 are relatively prime because the factors of 8 are 1, 2, 4, 8 and the factors of 15 are 1, 3, 5, 15, and the only shared factor is 1. Importantly, the numbers themselves do not need to be prime. The numbers 14 and 25 are both composite but are still relatively prime since they share no common prime factors. This concept is fundamental in number theory and has practical applications in cryptography and modular arithmetic.

How is the GCD used to determine if numbers are relatively prime?

The greatest common divisor is the largest positive integer that divides both numbers without leaving a remainder. If the GCD of two numbers equals 1, those numbers are relatively prime by definition. The most efficient method for computing the GCD is the Euclidean algorithm, which works by repeatedly replacing the larger number with the remainder of dividing the larger by the smaller. For instance, GCD(48, 35): 48 = 1 times 35 + 13, then 35 = 2 times 13 + 9, then 13 = 1 times 9 + 4, then 9 = 2 times 4 + 1, then 4 = 4 times 1 + 0. The last nonzero remainder is 1, confirming they are coprime.

Are consecutive integers always relatively prime?

Yes, any two consecutive integers are always relatively prime, and this can be proven mathematically. Suppose n and n+1 share a common factor d greater than 1. Then d would divide both n and n+1, which means d would also divide their difference: (n+1) - n = 1. But no integer greater than 1 can divide 1, creating a contradiction. Therefore consecutive integers are always coprime. This property extends to other patterns as well. For example, n and 2n+1 are always coprime, as are consecutive Fibonacci numbers. These relationships are foundational results in elementary number theory.

How are relatively prime numbers used in cryptography?

Relatively prime numbers are the cornerstone of RSA encryption, one of the most widely used public-key cryptosystems. In RSA, two large prime numbers p and q are multiplied to create n = p times q. The encryption exponent e must be coprime to phi(n) = (p-1)(q-1). The decryption key d is then the modular multiplicative inverse of e modulo phi(n), which exists precisely because e and phi(n) are coprime. Without the coprimality requirement, the inverse would not exist and decryption would be impossible. This application of number theory secures internet banking, email encryption, digital signatures, and virtually all secure online communications.

Can more than two numbers be relatively prime?

Yes, the concept of coprimality extends to sets of more than two numbers in two different ways. A set of numbers is mutually coprime (or pairwise coprime) if every pair within the set is coprime. A weaker condition is that the set is setwise coprime, meaning the GCD of all numbers together is 1. For example, 6, 10, and 15 are setwise coprime since GCD(6, 10, 15) = 1, but they are NOT pairwise coprime because GCD(6, 10) = 2. In contrast, 5, 7, and 11 are pairwise coprime since every pair has GCD = 1. The Chinese Remainder Theorem requires pairwise coprimality of moduli for its standard formulation.

How do you make two numbers relatively prime?

If two numbers are not relatively prime, you can reduce them to a coprime pair by dividing both by their GCD. For example, 12 and 18 have GCD = 6, so dividing both by 6 gives 2 and 3, which are coprime. This process is exactly what happens when you simplify a fraction: 12/18 becomes 2/3 in lowest terms because you divided by the GCD. In modular arithmetic, you sometimes need to find a number coprime to a given modulus. One approach is to select prime numbers, since a prime p is coprime to any number that is not a multiple of p. In RSA key generation, the encryption exponent is chosen to be coprime to the totient by selecting a prime like 65537.

References