# GCD and LCM calculator

> The GCD is the largest number that divides all inputs evenly. The LCM is the smallest number that all inputs divide into evenly.

Find the greatest common divisor (GCD) and least common multiple (LCM) for two or more integers. Supports any number of inputs.

**Interactive version:** https://onlinecalculator.me/math/gcd-lcm/
**Category:** Math

## Algorithm

**GCD** uses Euclid's algorithm (approximately 300 BC — one of the oldest algorithms still in use):

```
GCD(a, b):
  while b ≠ 0:
    a, b = b, a mod b
  return a
```

**LCM** is derived from GCD:

```
LCM(a, b) = |a × b| / GCD(a, b)
```

For more than two numbers, apply pairwise: GCD(a, b, c) = GCD(GCD(a, b), c).

## Examples

| Numbers | GCD | LCM |
|---------|-----|-----|
| 12, 18 | 6 | 36 |
| 4, 6 | 2 | 12 |
| 7, 13 | 1 | 91 |
| 12, 18, 24 | 6 | 72 |

## Frequently asked questions

### What is GCD?

GCD (greatest common divisor), also called GCF (greatest common factor) or HCF (highest common factor), is the largest positive integer that divides all given numbers without remainder. GCD(12, 18) = 6 because 6 is the largest number that divides both 12 and 18.

### What is LCM?

LCM (least common multiple) is the smallest positive integer that is divisible by all given numbers. LCM(4, 6) = 12 because 12 is the smallest number that both 4 and 6 divide into evenly.

### How is GCD calculated?

The calculator uses Euclid's algorithm: GCD(a, b) = GCD(b, a mod b), repeated until b = 0. It then reduces multiple numbers by applying GCD pairwise.

### What is the relationship between GCD and LCM?

For two numbers a and b: LCM(a, b) = |a × b| / GCD(a, b). This is why reducing the GCD first prevents overflow.

### How do I share my calculation?

Click "Share with my numbers" to copy a URL that reopens with your input.

## Sources

- [Greatest common divisor and the Euclidean algorithm](https://en.wikipedia.org/wiki/Greatest_common_divisor) — Wikipedia
- [Least common multiple (lcm(a,b) = |ab|/gcd(a,b))](https://en.wikipedia.org/wiki/Least_common_multiple) — Wikipedia

## Related calculators

- [Factorial calculator](https://onlinecalculator.me/math/factorial/) — n! for any non-negative integer.
- [Combinations calculator](https://onlinecalculator.me/math/combinations/) — C(n,k) combinations and P(n,k) permutations.
- [Average calculator](https://onlinecalculator.me/math/average/) — Mean, median, and mode from a list of numbers.
- [Standard deviation calculator](https://onlinecalculator.me/math/standard-deviation/) — Sample and population standard deviation.

---

Part of [onlinecalculator.me](https://onlinecalculator.me/) — free calculators that run entirely in your browser.
Machine-readable index: https://onlinecalculator.me/llms.txt
