GCD & LCM Calculator

Find the GCD and LCM of two integers. Decimals are rejected instead of silently truncated. Zero and negative inputs have stated rules.

Last updated: October 4, 2026

Tool

This tool will load here.

What this calculator does

GCD is the greatest common divisor: the largest integer that divides both inputs. LCM is the least common multiple: the smallest non-negative integer that both inputs divide, with a special case at zero. gcd(12, 18) is 6. lcm(12, 18) is 36. Those two numbers show up when you reduce a fraction or a ratio, which is why this GCD & LCM calculator sits next to those tools rather than inside them.

The form takes two integers. A decimal such as 12.5 is an error, not a silent cast to 12. That is the opposite of being helpful: truncation changes the question. Negatives are allowed; gcd uses absolute values. gcd(0, n) is |n|. lcm(0, n) is 0 when n is not also 0. gcd(0, 0) is 0 on this page; lcm(0, 0) is undefined and labeled that way.

Two inputs are enough for a first cluster. A list of twelve integers would need overflow checks on every pairwise lcm and a worse layout. You can run the tool again on (gcd_so_far, next). For the fraction that gcd is about to reduce, use the Fraction Calculator. For 12 : 18, use the Ratio Calculator.

How to use

  1. Enter the first integer.
  2. Enter the second integer.
  3. Calculate. Example is 12 and 18, which should show GCD 6 and LCM 36.

Scientific notation that is still an integer (for example 1e3) is accepted by the number parser only if it is a whole number. 1e-1 is not an integer.

Formula

GCD uses the Euclidean algorithm on absolute values: gcd(a, b) = gcd(b, a mod b) until b is 0. LCM for nonzero a and b is (|a| / gcd(a, b)) × |b|, computed so the multiply stays inside the safe integer range or the status refuses. That identity is why lcm can overflow even when gcd is small.

Example

12 and 18 → GCD 6, LCM 36. 7 and 13 → GCD 1, LCM 91. −12 and 18 → GCD 6, LCM 36. 0 and 15 → GCD 15, LCM 0. 0 and 0 → GCD 0, LCM undefined. 12.5 and 10 → error, not GCD 2.

gcd(12, 18) = 6
lcm(12, 18) = 36

Limits

  • Two integers per run.
  • Decimals are errors.
  • LCM overflow is an error, not a rounded float.
  • This is not a prime-factorization explorer.

GCD and LCM are related by gcd(a, b) × lcm(a, b) = |a × b| when a and b are nonzero. You can check a result with that identity. If the product of your gcd and lcm does not equal the absolute product of the inputs, one of the three numbers is wrong. The identity fails at zero, which is why 0 is documented instead of being forced through the same multiply.

Prime numbers have gcd 1 with any integer they do not divide. That is not a special mode; the Euclidean algorithm already returns 1. Coprime pairs still have an LCM equal to the absolute product. The GCD & LCM calculator reports both so you can see that relationship without a third tool.

Reducing 12/18 is the Fraction Calculator. Reducing 12 : 18 is the Ratio Calculator. Both use the same gcd idea this page isolates. Neither of those pages will show lcm(12, 18) = 36 on its own.

On this page

Related guides

Related solutions

Need another tool ?

Open the free tools — no signup.

FAQs

newsletter signup

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Innovative Solutions For Modern Needs
Copyright © 2026 Yallasolve. all rights reserved.