Compute GCD & LCM for any integers
Greatest common divisor and least common multiple of 2+ integers using BigInt for arbitrary precision. Shows the Euclidean algorithm trace. Runs entirely in your browser.
How to compute GCD and LCM
Greatest common divisor uses the Euclidean algorithm; least common multiple uses the identity a·b = gcd·lcm.
- 01
Enter integers
2+ values, separated by space, comma, or newline.
Inputs are treated as UTF-8 throughout the pipeline and validated client-side as you type — nothing dispatches until the value is well-formed.
inpututf-8client-sidevalidatedinput · textn · set48 180 72
loaded · parsedclient-side - 02
Euclidean GCD
Repeated mod until remainder is zero — fold across all values.
Each toggle re-computes through a memoised hook, so flipping options never resets your input and the UI stays snappy on large inputs.
gcdoptionslivememoisedtogglesgcd · memoisedfold · livegcd(a, b, c) = gcd(gcd(a,b), c)
options set · memoisedlive - 03
LCM from GCD
lcm(a,b) = |a·b| / gcd(a,b). Iterate for n values.
Randomness — where used — comes from
crypto.getRandomValues, neverMath.random. Heavy work sits inuseMemo.lcmcomputeinstantlocaldeterministiclcm · instantfold · computed(a/gcd)·b
computed · instantinstant - 04
Read the trace
Each line shows one Euclidean step until r=0.
Copy writes through
navigator.clipboardand downloads use aBlob— zero network traffic. Same input plus same options always yield the same bytes.tracecopydownloadzero-networkreproducibleok · copiedready · copiedgcd = 12
shipped · ready to shipsuccess
Pro tips for everyday utilities
Reach for crypto.getRandomValues
Cryptographically random for IDs, tokens, salts. Math.random is for animation and games, not security.
Mock data with seeds
Faker-style libraries can be seeded so tests are reproducible. Embed the seed in the fixture file.
Reference cards beat memory
Cheatsheets for Vim, Git, Docker, Linux signals are faster than man pages when you’re mid-flow.
Browser APIs vary
Touch events, gamepads, and clipboard differ across vendors. Feature-detect before use.
Persist in the right place
localStorage for user preferences, sessionStorage for transient state, IndexedDB for structured data.
When to use GCD & LCM
Fractions, scheduling, modular math, cryptography.
Reduce fractions
Divide top and bottom by gcd to simplify. Random values come from crypto.getRandomValues — cryptographically secure for tokens, salts, and session IDs. Math.random is deterministic enough for animations but predictable enough to be a security bug.
CSPRNG-backedSchedule sync
lcm of intervals gives the common cycle length. Pair with hashids, ULID, or UUID v7 when you need both random and sortable — useful for primary keys, public-facing IDs, and event log ordering without a sequence column.
reproducibleTile sizing
gcd of dimensions tells the largest square that tiles. Output is deterministic given the same seed, so fixtures and tests stay reproducible across CI runs and contributor machines. Embed the seed in the fixture file for full replay.
snappyModular inverses
gcd=1 confirms an inverse exists mod n. Heavy work runs through useMemo so the UI stays snappy on large inputs. Same input + same options yields identical bytes — the kind of stability snapshot tests rely on.
feature-detectedBuffer alignment
lcm of strides for SIMD/DMA alignment. Storage tools persist to the right backend: localStorage for user preferences, sessionStorage for transient state, IndexedDB for structured data. Pick the right shelf and quota worries disappear.
deterministicMusic ratios
Reduce rhythm ratios with gcd. Browser feature detection: clipboard, fullscreen, gamepad, and Web Bluetooth APIs gracefully fall back when unavailable. No surprise white screens on Safari or older Firefox.
production-readyFrequently asked questions
Something missing?
Tell us what you need. We ship the top requests every two weeks.