GCD and LCM of multiple numbers free
For twelve, eighteen and twenty-four, the greatest common divisor is 6 and the least common multiple is 72, both from one list. Enter two or more non-zero integers and get the two answers side by side. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Numbers
- 12, 18, 24
- Gcd
- 6
- Lcm
- 72
The GCD and LCM calculator takes a list of integers and returns both the greatest common divisor and the least common multiple of the whole set. It uses the Euclidean algorithm for GCD and reduces LCM pairwise as |a/g|*b so intermediate products stay smaller.
What GCD and LCM mean together
The greatest common divisor is the largest positive integer that divides every number in the list without remainder. The least common multiple is the smallest positive integer that is a multiple of every number. For two values the classic identity gcd(a,b)*lcm(a,b)=|a*b| holds; for longer lists both measures are built by folding the same binary steps left to right.
Returning both fields in one response avoids a second round-trip when you need fractions in lowest terms and a common period in the same pipeline. Teachers, game loops, and sample-rate tools all benefit from a single structured answer that keeps the two related measures aligned rather than recomputing one from the other with ad-hoc scripts.
How the algorithm stays exact
GCD uses Euclid: replace (a,b) with (b, a mod b) until the remainder is zero, always on absolute values so signs never change the result. LCM is computed pairwise as abs(a)/gcd(a,b)*abs(b), dividing before multiplying to limit intermediate growth. Zero is rejected because LCM with zero is undefined in this contract.
Where you use it
Game and animation code schedules loops on a shared LCM of frame lengths. Engineers simplify multi-denominator rates or sample-clock ratios without a spreadsheet. Because the capability is pure parse-tier arithmetic there is no network hop, no randomness and no floating-point lottery beyond ordinary integer ranges.
What you can do with it
Homework checks
Verify GCD and LCM answers for lists longer than two without hand-folding Euclid steps.
Shared periods
Find the least common cycle length for timers, animations or sample rates that must meet on the same tick.
Rate simplification
Reduce multi-denominator ratios by computing a single GCD across all terms first.
FAQ
Is this free?
Yes. Tier A runs entirely in your browser without an account.
How many numbers can I send?
At least two integers. There is no special upper bound beyond ordinary request size; GCD and LCM fold pairwise across the whole array.
Are negative numbers allowed?
Yes. The tool uses absolute values for GCD and returns a non-negative LCM.
How are the GCD and LCM of two numbers related?
For two numbers, the GCD times the LCM equals the absolute value of their product. For longer lists there is no such shortcut, so both values are built step by step, pair after pair, from left to right.
What is the LCM used for in practice?
To find when cycles of different lengths line up again, such as timers, animation loops or sample rates that must land on the same tick. For twelve, eighteen and twenty-four, the shared cycle is 72.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/gcd-lcm \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"numbers":[12,18,24]}'const res = await fetch("https://api.kit.forhosting.com/math/gcd-lcm", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"numbers": [
12,
18,
24
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/gcd-lcm",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"numbers": [
12,
18,
24
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/gcd-lcm", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"numbers":[12,18,24]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"numbers":[12,18,24]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/gcd-lcm", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"numbers": [
12,
18,
24
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.gcd_lcm",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
How the algorithm stays exact
Non-integers, non-finite values and arrays shorter than two elements raise invalid_input with a clear message so callers can fix the payload without guessing.
Where you use it
Pair the free browser run with the priced API when you need the same result inside automated pipelines at $0.002 per successful item.
Technical questions
Why is zero rejected?
LCM involving zero is undefined under this contract, so any zero yields invalid_input.
Does it call the network?
No. The parse engine keeps everything on-device.