🔢 GCD Calculator
Compute the greatest common divisor (GCD) for two or more integers using the Euclidean algorithm. This tool supports large integers via BigInt, shows step-by-step logs, computes extended GCD (Bézout coefficients) for two inputs, and can produce the LCM for two integers.
How to Compute the GCD — Online GCD Calculator Tutorial (Euclidean algorithm, extended GCD, LCM)
The greatest common divisor (GCD) is the largest integer that divides two or more integers without leaving a remainder. It’s a fundamental concept in number theory, central to simplification of fractions, modular arithmetic, cryptography, and many algorithmic tasks. This tutorial walks you through the Euclidean algorithm, the extended GCD (Bézout coefficients), computing the least common multiple (LCM), practical examples, and how to use this online GCD calculator effectively.
Why GCD matters
Understanding the GCD helps in simplifying fractions (for example reducing 48/180 by dividing numerator and denominator by gcd(48,180)=12), computing modular inverses (vital for cryptography and modular arithmetic), and solving linear Diophantine equations (ax + by = c). Efficient GCD algorithms are extremely fast — the Euclidean algorithm runs in time logarithmic in the input size — making GCD checks feasible even for very large numbers.
The Euclidean algorithm (step-by-step)
The Euclidean algorithm computes gcd(a, b) by repeated division: replace (a, b) with (b, a mod b) until the remainder is zero. The last non-zero b is the gcd. For example, to compute gcd(48, 180):
180 = 48 × 3 + 36 48 = 36 × 1 + 12 36 = 12 × 3 + 0 → gcd = 12
That sequence shows why the algorithm is efficient: each remainder is strictly smaller than its predecessor, and the number of steps grows slowly with the size of the input.
Extended Euclidean algorithm and Bézout coefficients
Beyond the gcd, the extended Euclidean algorithm computes integers x and y such that ax + by = gcd(a,b). These Bézout coefficients are essential when computing modular inverses: if gcd(a,m) = 1, then x (mod m) is the modular inverse of a modulo m. For example, for a=30 and b=11, the algorithm finds x and y such that 30x + 11y = 1, and x mod 11 gives 30⁻¹ (mod 11).
LCM and its relation to GCD
For two nonzero integers a and b, the least common multiple (LCM) relates to the GCD via the formula:
lcm(a,b) × gcd(a,b) = |a × b|
This relation provides a convenient way to compute LCM once the GCD is known, and it avoids expensive factorization when values are large.
How the online GCD Calculator works
This calculator accepts two or more integers (commas or spaces allowed), parses them as JavaScript BigInt for exact integer arithmetic, and uses the Euclidean algorithm to compute the gcd. If two numbers are supplied it also runs the extended algorithm to return Bézout coefficients and computes the LCM using the relation above. Optionally, the tool prints a step-by-step trace of the Euclidean reductions to help you learn and verify results.
Step-by-step usage guide
- Enter integers separated by commas or spaces (e.g.,
48, 180or270 192 48). - Toggle “Show step-by-step” to display the Euclidean algorithm trace during calculation.
- Click Calculate. The result panel shows the gcd and additional results (LCM and Bézout coefficients for two numbers).
- Use Download CSV to save inputs, gcd, lcm and step logs; or Copy Result to copy to clipboard.
Worked example — three numbers
Find gcd(210, 462, 588). The calculator reduces pairwise:
g1 = gcd(210, 462) = 210 gcd(g1, 588) = gcd(210, 588) = 210
Therefore gcd(210,462,588) = 210. Try these values in the calculator to see each Euclidean step expanded.
Worked example — extended GCD & modular inverse
Suppose you need the modular inverse of 17 modulo 3120 (phi(53×61)). First compute gcd(17,3120) which equals 1. Extended GCD supplies x such that 17x + 3120y = 1. The value x modulo 3120 is the inverse of 17. Use the calculator with the two integers 17 and 3120 to see the Bézout coefficients and extract the modular inverse.
Practical tips and common pitfalls
- Input formatting: Remove commas and any non-digit characters except leading minus signs. Example: use
1000000not1,000,000. - Zero behavior: gcd(0,a) = |a| and gcd(0,0) is reported here as 0 by convention.
- Negative numbers: Signs do not change gcd value since absolute values are used; Bézout coefficients adapt to original signs.
- Large integers: BigInt keeps results exact, but browser CPU and memory limits may affect extremely large or numerous inputs.
Applications in computing and engineering
GCD shows up in fraction reduction, scheduling problems (finding common cycles), signal processing (synchronizing frequencies), public-key cryptography (modular inverses), and computational number theory. Being able to compute GCDs quickly and reliably is a small but essential building block in many systems.
When to use server-side tools
For batch processing of thousands of very large integers, cryptographic key generation, or when you require advanced factorization, prefer server-side libraries (GMP, OpenSSL, Python’s gmpy2) or compiled code that uses optimized big-integer routines. The browser tool is ideal for learning, verification, single-use checks and moderate-size tasks.
Conclusion
This online GCD calculator implements proven algorithms (Euclidean & extended) with exact BigInt arithmetic, step-by-step logs for learning, and export options for documentation. Use it to quickly compute gcd, recover Bézout coefficients for modular arithmetic, and compute LCMs with confidence. If you need a tailored workflow or server-side integration, we can help design one using the same algorithms but with higher performance libraries.
Frequently Asked Questions (FAQs)
Enter integers separated by commas or spaces (for example:
48,180 or 48 180 12).Yes — the GCD uses absolute values, so negative signs do not affect the result.
Bézout coefficients let you compute modular inverses: if gcd(a,m)=1 then x from ax+my=1 is the modular inverse of a mod m.
For two integers a and b (not both zero):
lcm(a,b) × gcd(a,b) = |a × b|. The tool computes LCM using this relation for two integers.Yes — the tool reduces pairwise: gcd(a,b,c,...) = gcd(gcd(a,b),c,...). Optionally show step logs to follow pairwise reductions.
Yes — using JavaScript BigInt arithmetic yields exact integer results within practical browser limits.
gcd(0,0,...) is reported as 0 in this tool. If at least one input is nonzero, the GCD equals the gcd of the nonzero values.
Yes — check the "Show step-by-step" box to display the Euclidean reductions for each pair used in the reduction process.
Yes — extended GCD gives a particular solution to ax + by = gcd(a,b); scaling provides solutions to ax + by = c when gcd divides c.
Yes — use the Download CSV button after computing to save inputs, gcd, lcm and step logs for documentation or reporting.