How the Relatively Prime Calculator works
Two integers a and b are relatively prime (also called coprime) when their greatest common divisor is 1: gcd(a, b) = 1. This has nothing to do with whether a or b are prime themselves — it only means they share no common positive factor larger than 1. This calculator computes gcd(a, b) with the Euclidean algorithm, reports whether the pair is relatively prime, and also derives the least common multiple (LCM) and the reduced ratio a : b.
The Euclidean algorithm
The fastest way to find gcd(a, b) is the Euclidean algorithm: divide the larger number by the smaller one and keep the remainder, then repeat with (smaller number, remainder) until the remainder hits 0 — the last nonzero remainder is the GCD. For example, gcd(14, 9): 14 mod 9 = 5, then 9 mod 5 = 4, then 5 mod 4 = 1, then 4 mod 1 = 0, so gcd(14, 9) = 1, which means 14 and 9 are relatively prime. The calculator uses negative-safe absolute values, so gcd(-14, 9) still returns 1.
Determining if two numbers are relatively prime
Once gcd(a, b) is known, the relatively-prime check is simple: if the GCD equals 1, the numbers are relatively prime; any GCD greater than 1 means they share that value as a common factor and are not relatively prime. From the same GCD, the calculator derives two useful bonus values: the LCM, using lcm(a, b) = |a × b| / gcd(a, b), and the fully reduced ratio a/gcd(a,b) : b/gcd(a,b), which is exactly how you would simplify the fraction a/b to lowest terms.
Common mistakes
- Confusing "relatively prime" with "prime": 14 and 9 are relatively prime even though neither is a prime number — relatively prime describes a pair, not a single number's primality.
- Assuming shared even/odd parity matters: two odd numbers can still share a large common factor (15 and 9 both share 3), and one even plus one odd number can still be relatively prime (8 and 9).
- Forgetting the zero case: gcd(0, n) = |n|, so 0 is relatively prime only to 1 or -1, and gcd(0, 0) is undefined.
Real-world applications
- Simplifying fractions to lowest terms uses the same GCD computed here — divide numerator and denominator by gcd(a, b).
- Cryptography (including RSA key generation) relies on choosing exponents that are relatively prime to a modulus.
- Gear and pulley design uses coprime tooth counts so that two meshing gears don't repeatedly pair the same teeth, spreading out wear evenly.
- Scheduling and cycle problems (for example, finding when two repeating events next align) use the LCM, which is smallest when the two numbers are relatively prime.