GCD & LCM Calculator

Calculate the greatest common divisor and least common multiple of two or more integers exactly. Handle large integers, negatives and zero, then copy or save TXT and JSON.

How to use

  1. Enter the list of integers.
  2. Calculate and review the greatest common divisor and least common multiple.
  3. Check the inputs against the results and optionally save text or JSON.

Enter integers

Separate plain integers with line breaks, spaces or tabs. Use 2–1,000 integers, each with up to 1,000 digits excluding its sign. Decimals, exponents, commas and fraction notation are not supported. UTF-8 input limit: 1 MB.

LCM limit: 10,000 digits. TXT and JSON output: 16,000 bytes each. Inputs and results are neither stored nor sent.

Results

Try a use case and check the result

Check GCD and LCM conventions for signed integers and lists containing zero.

Example buttons replace the inputs and settings above and calculate. Restore previous input steps back one example at a time. After trying multiple examples, repeat restore to return to your original input. This history is lost when the page closes.

Compare −6, 9 and −12 by absolute value

Input and settings

Integers: -6 9 -12 (whitespace separated)

Expected result

GCD: 3 / LCM: 36

Include a zero: LCM becomes zero

Input and settings

Integers: 0 6 9

Expected result

GCD: 3 / LCM: 0

How to read the result

Negative inputs use their absolute values. Three divides 6, 9 and 12, while 36 is their least positive common multiple. This tool defines LCM as zero when any input is zero; do not interpret that as a positive repeat interval. Its all-zero GCD convention is also zero.

Scope and limits

Separate 2–1,000 integers with spaces, newlines or tabs. Commas, decimals and exponents are unsupported. Each integer allows 1,000 digits including leading zeros but excluding the sign; total input is limited to 1,000,000 UTF-8 bytes. BigInt gives exact arithmetic, capped at 10,000 LCM digits and 16,000 output bytes. Finding a zero does not skip validation of the remaining input.

Verification: existing functions cover absolute values, mixed/all zeros, digit/count limits and exact large integers. Browser checks compare both Worker results, JSON downloads and restoration after multiple examples.

Continue with the next task

Details and limits

For the example 12, 18, 24, the GCD is 6 and the LCM is 72. The GCD is the greatest positive integer dividing every value; for positive inputs, the LCM is the smallest positive integer divisible by every value.

Negative inputs use their absolute values. For -6 and 9, the GCD is 3 and LCM 18. Duplicates count as inputs but do not change the GCD or LCM.

If any input is zero, the GCD is obtained from the remaining integers and the LCM is zero. For an all-zero list, this tool defines both GCD and LCM as zero. Use positive integers when modeling repeating intervals or periods.

Inputs and results remain exact integer strings without rounding. An LCM exceeding 10,000 digits produces an error and cannot be saved as a partial result. All inputs are validated before applying the zero-LCM rule, so a zero anywhere prevents a false overflow error from an intermediate product.

TXT contains two lines labeled GCD and LCM. JSON contains count, GCD, LCM and the negative/zero conventions; it does not include the original list. Large JSON results are strings. Files use UTF-8 without a BOM or added trailing newline.

Editing cancels in-progress work and clears the previous result. Cancel retains the input; Reset clears input and results.

Frequently asked questions

Can I use negative numbers or zero?

Negatives are treated as absolute values. Any zero makes the LCM zero; this tool also defines the all-zero GCD as zero.

What if the list contains 1?

The GCD is 1. The LCM comes from the other integers, unless any zero makes it zero.

Can I save a large result without rounding?

Yes. Copy and save include the complete result up to the 10,000-digit LCM limit. Above that limit the tool reports an error instead of truncating the result.

Related tools

Inputs and storage

Keep any content you need before clearing. This tool does not autosave inputs or results. Reloading or closing the page, clearing inputs or resetting may discard your work.

Favorites and language preferences are stored separately and may be lost when site data is cleared. Tool resets and site-data deletion do not delete files already downloaded to your device.

Explore tools & games

All 120 tools · 16 games

All 120 tools · 16 games

Text & writing 26

Calculators & converters 22

Date & time 12

Images & PDF 26

Data & web 28

Random & handy 6

Games 16