Relatively Prime Calculator
Solve relatively prime problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Relatively Prime Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: Two numbers a and b are relatively prime if GCD(a, b) = 1
Worked example โ 15 and 28 ARE relatively prime (GCD = 1), LCM = 420
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 Prime factors of 28: 2, 2, 7 No common prime factors exist. Euclidean algorithm: GCD(28, 15) -> 28 = 1 x 15 + 13 -> 15 = 1 x 13 + 2 -> 13 = 6 x 2 + 1 -> 2 = 2 x 1 + 0 GCD = 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 Prime factors of 36: 2, 2, 3, 3 Common prime factors: 2, 2, 3 -> GCD = 12 Euclidean algorithm: GCD(36, 24) -> 36 = 1 x 24 + 12 -> 24 = 2 x 12 + 0 GCD = 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.
What is the Euler totient function and how does it relate to coprimes?
The Euler totient function, written as phi(n), counts how many integers from 1 to n are relatively prime to n. For example, phi(12) = 4 because only 1, 5, 7, and 11 share no common factors with 12 out of the integers from 1 to 12. For a prime number p, phi(p) = p - 1 since every number less than a prime is coprime to it. The totient function is multiplicative: if a and b are coprime, then phi(a times b) = phi(a) times phi(b). This function plays a critical role in RSA encryption, where the totient of the product of two large primes determines the encryption and decryption keys.
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.
What is the relationship between GCD and LCM?
The greatest common divisor and least common multiple of two numbers are connected by the elegant formula: GCD(a, b) times LCM(a, b) = a times b. This means LCM(a, b) = (a times b) / GCD(a, b). When two numbers are relatively prime (GCD = 1), their LCM equals their product. For example, since GCD(8, 15) = 1, LCM(8, 15) = 120 = 8 times 15. When numbers share factors, the LCM is smaller than their product. For GCD(12, 18) = 6, LCM(12, 18) = 216/6 = 36. This relationship provides an efficient way to compute the LCM once you know the GCD.
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 does the Chinese Remainder Theorem use coprime numbers?
The Chinese Remainder Theorem states that if you have a system of simultaneous congruences with pairwise coprime moduli, then there exists a unique solution modulo the product of all the moduli. For example, find x such that x is congruent to 2 mod 3, x is congruent to 3 mod 5, and x is congruent to 2 mod 7. Since 3, 5, and 7 are pairwise coprime, a unique solution exists modulo 105 (which is 3 times 5 times 7), and that solution is x = 23. This theorem has applications in computer science for parallel computing, in signal processing, and in solving scheduling problems where events repeat at different intervals.
What is the probability that two random numbers are coprime?
A remarkable result in number theory states that the probability of two randomly chosen positive integers being coprime is 6 divided by pi squared, approximately 60.79%. This result, proven by Euler, connects number theory to the constant pi in a surprising way. More precisely, the density of coprime pairs among all integer pairs equals the reciprocal of the Riemann zeta function evaluated at 2, which is 1/zeta(2) = 6/pi squared. For practical purposes, if you pick two random numbers between 1 and 1000, roughly 608 out of 1000 such pairs will be coprime. This probabilistic result has applications in random number generation and Monte Carlo methods for estimating pi.
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
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐งฎPrime Factorization Calculator
Calculate prime factorization with inputs, formulas, and instant results.
๐งฎPrime Number Calculator
Calculate prime number with inputs, formulas, and instant results.
๐งฎMersenne Prime Finder
Calculate mersenne prime finder with inputs, formulas, and instant results.
๐งฎPrime Counting Function Calculator
Calculate prime counting function with inputs, formulas, and instant results.
๐งฎGreatest Common Factor Calculator
Find the GCF (GCD) of two or more numbers using prime factorization and Euclidean algorithm.
๐งฎLeast Common Multiple Calculator
Find the LCM of two or more numbers using prime factorization and the GCF method.
๐งฎMiller-Rabin Primality Test Calculator
Test if large numbers are prime using the Miller-Rabin probabilistic primality test.
๐งฎEuler Totient Calculator
Calculate Euler totient function for any positive integer with prime factorization.