# GCD and LCM Calculator

> Computes the greatest common divisor (highest common factor) and least common multiple of two or more integers with the Euclidean algorithm.

- Calculator id: `gcd-lcm` · Category: Math (`math`) · Tool name: `calculate_gcd_lcm`
- Canonical page: https://tttkmbb.com/math/gcd-lcm · This document: https://tttkmbb.com/math/gcd-lcm.md · JSON definition: https://tttkmbb.com/math/gcd-lcm.json

## Purpose

Computes the greatest common divisor (highest common factor) and least common multiple of two or more integers with the Euclidean algorithm.

**Use when:** You need the GCD/HCF or LCM of a list of integers, e.g. to reduce fractions, find a common denominator or check whether numbers are coprime.

**Do not use when:** You need the prime factors themselves (use prime-factorization) or want to reduce a single fraction (use fraction-simplifier).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `numbers` | number_list |  | required | Two or more integers, comma-separated (e.g. 12, 18, 24). Negative values are treated by their absolute value. |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `gcd` | integer |  | Greatest common divisor of all the numbers. |
| `lcm` | integer |  | Least common multiple of all the numbers. |
| `coprime` | boolean |  | true when the GCD is 1 (the numbers share no common factor). |

## Formula

`gcd(a, b) by the Euclidean algorithm (gcd(a, b) = gcd(b, a mod b)); lcm(a, b) = |a × b| / gcd(a, b); both are folded over the list: gcd(a, b, c) = gcd(gcd(a, b), c)`

## Data Sources

- Wikipedia – Greatest common divisor — https://en.wikipedia.org/wiki/Greatest_common_divisor (reference, retrieved 2026-09-23)
- Wikipedia – Least common multiple — https://en.wikipedia.org/wiki/Least_common_multiple (reference, retrieved 2026-09-23)
- Wolfram MathWorld – Greatest Common Divisor — https://mathworld.wolfram.com/GreatestCommonDivisor.html (reference, retrieved 2026-09-23)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/gcd-lcm?numbers=…`
- `POST https://tttkmbb.com/api/v1/calculate/gcd-lcm` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/gcd-lcm · OpenAPI operationId `calculate_gcd_lcm` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "gcd-lcm", "inputs": {…}}`

## Example

- 12 and 18: inputs `{"numbers":[12,18]}` → `{"gcd":6,"lcm":36,"coprime":false}`
- 4, 6 and 8: inputs `{"numbers":[4,6,8]}` → `{"gcd":2,"lcm":24,"coprime":false}`

```
GET https://tttkmbb.com/api/v1/calculate/gcd-lcm?numbers=12%2C18
```

## Limitations

You need the prime factors themselves (use prime-factorization) or want to reduce a single fraction (use fraction-simplifier). All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Is HCF the same as GCD?**

Yes. Highest common factor (HCF), greatest common factor (GCF) and greatest common divisor (GCD) are the same quantity.

**How large can the numbers be?**

Any integers whose LCM stays below 2^53 (about 9 × 10^15); larger results cannot be represented exactly and return an error.

## Related

- [Fraction Simplifier](https://tttkmbb.com/math/fraction-simplifier.md) — Reduce a fraction by its GCD.
- [Prime Factorization Calculator](https://tttkmbb.com/math/prime-factorization.md) — See the prime factors behind the GCD and LCM.
- [Ratio Calculator](https://tttkmbb.com/math/ratio.md) — Simplify a ratio by dividing by the GCD.
