# GCD & LCM Calculator

- **URL:** https://codeasystem.com/calculators/math/gcd-lcm-calculator/
- **Category:** math
- **Description:** Find the greatest common divisor of two integers with Euclid’s algorithm, plus the least common multiple derived from it.
- **Primary output:** Greatest common divisor (GCD): 6

## Inputs
- First integer (name: `a`, type: number, example: 48)
- Second integer (name: `b`, type: number, example: 18)

## Outputs
- Greatest common divisor (GCD): 6
- Least common multiple (LCM): 144
- Product a × b: 864

## Formula / methodology
```
GCD: Euclid’s algorithm; GCD(a, b) = GCD(b, a mod b)
LCM = |a × b| / GCD(a, b)
```

Euclid’s algorithm repeatedly replaces the pair (a, b) with (b, a mod b) until the remainder hits zero; the surviving value is the greatest common divisor. The LCM then falls out for free from the identity |a×b| = GCD × LCM, dividing out the shared factors so nothing is double-counted.

## Assumptions & limitations
- Inputs must be non-zero integers within ±10¹⁵ to keep products exact.
- Signs are ignored; results are positive by convention.
- Both GCD and LCM are always shown together.

## How to use
1. **Enter two whole integers**; Any magnitude up to about 15 digits works instantly.
2. **Read the GCD**; That is the largest integer dividing both inputs evenly.
3. **Use the LCM row**; Smallest number both inputs divide into; handy for adding fractions or aligning cycles.

## Example
For 48 and 18, Euclid reduces (48,18) → (18,12) → (12,6) → (6,0), giving GCD 6; and the LCM follows as 144.

Result for these inputs:

```
Greatest common divisor (GCD): 6
```

## About this calculator
### Why Euclid still wins after 2,300 years

One modulo operation per step shrinks the problem geometrically, so even 20-digit pairs finish in a handful of iterations. It is among the oldest recorded algorithms and remains the fastest practical method in every programming language.

### Fractions and gears

Adding 5/18 + 7/48 wants the LCM as a common denominator; simplifying 48/18 wants the GCD. The same pair of numbers answers both directions, which is why this calculator always reports both.

### Where you meet them outside class

Event scheduling (two buses every 12 and 18 minutes meet every LCM 36 minutes), gear tooth design, cryptographic key checks and music rhythm alignment all reduce to GCD/LCM questions.

## FAQs
### Does order matter?

No; GCD and LCM are symmetric in their two arguments.

### Can I use negative numbers?

Results are defined on magnitudes; the calculator reports the positive value regardless of input signs.

### What if both numbers share no common factor?

They always share 1, so coprime inputs simply return GCD 1 and LCM equal to their product.

### Why is my huge product slightly off?

Beyond roughly 10¹⁵ floating-point multiplication loses exactness; the calculator caps inputs to stay exact.

## Related calculators
- [Ratio Calculator](https://codeasystem.com/calculators/math/ratio-calculator/)
- [Decimal to Fraction Calculator](https://codeasystem.com/calculators/math/decimal-to-fraction-calculator/)
- [Factorial Calculator](https://codeasystem.com/calculators/math/factorial-calculator/)

---
Last updated: 2026-08-23 · Version: 1.0.0 · [HTML version](https://codeasystem.com/calculators/math/gcd-lcm-calculator/)
