ForHosting KIT · Math

Least common multiple calculator

Get the smallest positive number that two integers both divide: the least common multiple of 12 and 18 is 36, so machines cycling every 12 and every 18 minutes line up every 36 minutes. The greatest common divisor, 6, comes with it. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
A
12
B
18
You get
Gcd
6
Lcm
36

Zero, decimals and non-numeric values are rejected with a clear error, and nothing is stored.

What the least common multiple actually answers

The least common multiple of two integers is the smallest positive number that is a multiple of both. It is the answer to a family of questions that look different but are the same problem: when do two repeating events coincide, what is the smallest batch size that splits evenly into two packagings, what common denominator do two fractions need before they can be added. Two machines cycling every 12 and every 18 minutes realign every 36 minutes, because 36 is the LCM of 12 and 18.

A kitchen tiling a wall with tiles of two lengths finds the first length where both patterns meet at the same joint. Negative inputs are handled by sign: the LCM is always reported as a positive integer, since multiples of a number are defined up to sign and the useful answer is the magnitude.

How it is computed, and why it stays exact

The computation goes through the greatest common divisor. Euclid's algorithm finds the GCD by repeated remainder — gcd(12, 18) is 6 — and the LCM follows from the identity lcm(a, b) = |a / gcd(a, b) × b|. The division is deliberately done before the multiplication: 12 divided by 6 is 2, and 2 times 18 is 36, so the intermediate values stay small instead of blowing up to the full product first.

This matters because JavaScript integers are exact only up to 2^53 − 1. Inputs that are zero, fractional, non-finite or not numbers at all are rejected the same way — a zero has no meaningful common multiple, and a decimal has no place in integer arithmetic.

Where it fits in real work

Scheduling and manufacturing are the two everyday homes of this calculation. In scheduling, the LCM of two periods tells you when two timers, shifts or maintenance windows coincide, which is the first thing you need before planning around the collision. In production, it gives the smallest run size that consumes whole packages of two components, so nothing is left over.

Developers also use it under the hood: adding fractions requires a common denominator, and the least one keeps the arithmetic small; synchronizing periodic tasks in code reduces to the same question.

Align two repeating schedules

Find when two cycles of different lengths next coincide — the LCM of 12 and 18 minutes is 36, so both events fire together every 36 minutes.

Size a batch with no leftovers

Compute the smallest production run that consumes whole boxes of two components when one comes in packs of 24 and the other in packs of 30.

Add fractions with the smallest denominator

Use the LCM of the two denominators as the common denominator, keeping the numerators small and the arithmetic exact.

What is the least common multiple of two numbers?

The smallest positive integer that both numbers divide exactly. For 12 and 18 it is 36, because 36 is a multiple of both and no smaller positive number is.

Can I use negative integers?

Yes. Signs are handled by taking absolute values internally; the LCM is always returned as a positive integer, since multiples are defined up to sign.

How large can the inputs be?

Each input must be a safe integer (absolute value up to 9007199254740991), and the resulting LCM must also fit in that range. Larger results are rejected explicitly rather than rounded.

Is the result exact?

Yes. The computation uses Euclid's algorithm and integer division, never floating-point approximation, and the response also includes the GCD so you can verify: lcm × gcd equals the absolute product of the inputs.

Why is the greatest common divisor shown as well?

Because the least common multiple is built from it. For 12 and 18 the divisor is 6: dividing 12 by 6 gives 2, and 2 times 18 gives 36. Dividing first keeps the numbers small instead of multiplying the full product.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/common-multiple

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/common-multiple \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":12,"b":18}'
{
  "a": 12,
  "b": 18
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.common_multiple",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs_value9007199254740991
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

The least common multiple API takes two nonzero integers and returns the smallest positive integer that both divide exactly — computed with exact integer arithmetic, not floating point, so the answer is precise for every input within the safe integer range. It also reports the greatest common divisor used in the computation, because the two values travel together: LCM times GCD equals the absolute product of the two inputs. The same code that answers the API runs free in your browser on this page, so you can check a pair of numbers by hand and only pay — $0.002 per request — when you automate it.

What the least common multiple actually answers

The least common multiple calculator endpoint computes that value in one call, exactly, for any two integers within the safe integer range.

How it is computed, and why it stays exact

The endpoint guards that boundary twice: each input must itself be a safe integer, and the resulting LCM must be one too, otherwise the request is rejected with an explicit error rather than silently returning a rounded wrong answer.

Where it fits in real work

The API is stateless and deterministic — the same pair always returns the same answer — so it is safe to cache and safe to assert against in tests. It runs on the edge for $0.002 per request, and the identical algorithm runs free in the browser on this page for interactive use.

What does it cost?

$0.002 per request. It is also free to run in your browser on this page — the same algorithm, no account needed.

Why does it reject zero?

The least common multiple is defined for nonzero integers: with a zero input there is no positive integer that both divide in the intended sense, so the request fails with invalid_input instead of returning a misleading value.

Read the full KIT documentation →