🔧 Operation
📝 Numbers (comma or space separated)
Enter 2 to 32 integers. Negative values are normalized to absolute values.
📝 Number to factorize
Enter a positive integer between 2 and 1012.
📤 Result
Euclidean Steps
| a | b | q | r |
|---|---|---|---|
| {{ step.a }} | {{ step.b }} | {{ step.q }} | {{ step.r }} |
📤 Result
Pairwise Reduction
| a | b | gcd | lcm |
|---|---|---|---|
| {{ step.a }} | {{ step.b }} | {{ step.gcd }} | {{ step.lcm }} |
📤 Prime Factorization
Factor Table
| Prime | Exponent |
|---|---|
| {{ entry.prime }} | {{ entry.exponent }} |
Result will appear here as you type.
ℹ️ About GCD / LCM Calculator
Definitions
This calculator works with three core number-theory operations for integer inputs:
- GCD, greatest common divisor, is the largest positive integer that divides every input without a remainder. It is also called the highest common factor (HCF).
- LCM, least common multiple, is the smallest positive integer that is a multiple of every non-zero input.
- Prime factorization writes an integer greater than 1 as a product of prime powers, such as
360 = 23 × 32 × 5.
Use it for quick GCD and LCM answers, step-by-step Euclidean reductions, and compact prime factor tables that are easy to copy into notes or code comments.
How the calculations work
GCD mode uses the Euclidean algorithm, the classic repeated-remainder method described in Euclid's Elements, Book VII, Proposition 2. For two numbers, divide the larger by the smaller, keep the remainder, and repeat until the remainder is zero. The last non-zero divisor is the GCD.
Multi-number GCD and LCM calculations are reduced pairwise: gcd(a, b, c) = gcd(gcd(a, b), c) and lcm(a, b, c) = lcm(lcm(a, b), c). LCM mode uses lcm(a, b) = |a × b| / gcd(a, b), then records each intermediate pair.
Prime factorization uses trial division: remove all factors of 2, then test odd divisors up to √n. The uniqueness of prime decomposition is the modern form of the idea connected to Euclid's Elements, Book IX, Proposition 14.
Worked examples
For 12, 18, 24, the common divisors are limited by 12, and the largest divisor shared by all three numbers is 6. The smallest positive multiple shared by all three is 72, so the calculator returns GCD = 6 and LCM = 72.
A Euclidean example for gcd(1071, 462) is:
1071 = 2 * 462 + 147 462 = 3 * 147 + 21 147 = 7 * 21 + 0 gcd = 21
In factorization mode, 840 becomes 23 × 3 × 5 × 7. From that form you can also inspect GCD/LCM by prime powers: take the smallest exponent for GCD and the largest exponent for LCM.
Practical use cases
- Fraction reduction: divide a numerator and denominator by their GCD to put the fraction in lowest terms.
- Scheduling and cycles: use LCM to find when repeating jobs, alarms, rotations, or polyrhythms align again.
- Ratios and proportions: use GCD to simplify integer ratios before scaling recipes, gear ratios, or layout grids.
- Modular arithmetic: check whether numbers are coprime, simplify congruences, or prepare examples for the Chinese remainder theorem.
- Number-theory study: compare Euclidean steps with prime factors to see why the same GCD/LCM result appears from both methods.
Limits and edge cases
- GCD and LCM modes accept 2 to 32 finite integers. Negative inputs are normalized with absolute value.
- GCD accepts zero values unless every input is zero, because
gcd(0, 0, ...)is undefined here. - LCM rejects zero because this tool reports the least positive common multiple.
- Browser input is limited to JavaScript safe integers, up to
Number.MAX_SAFE_INTEGER, so decimal integers are represented exactly before the calculation starts. - LCM intermediates use
BigIntarithmetic; results larger than the safe integer range are returned as strings. - Prime factorization accepts one integer from
2through1012. Larger values are intentionally blocked to keep the browser responsive.
This is an educational calculator, not a cryptographic factoring service. It is useful for classroom examples and everyday integer math, but it is not designed to factor large RSA-style semiprimes.
API Usage Example:
POST /api/tools/math/gcd-lcm-calculator
Content-Type: application/json
{
"operation": "gcd",
"numbers": [
12,
18,
24
]
}