Integer Calculator — GCD, LCM, Division & Arithmetic
Enter two integers to instantly see their GCD (greatest common divisor) and LCM (least common multiple), integer division quotient and remainder, and basic arithmetic — all shown on a number line.
The largest integer that divides both a and b exactly
How does this calculator work?
Enter two integers a and b. GCD is found via the Euclidean algorithm (keep taking remainders until zero). LCM = |a × b| / GCD. Integer division gives quotient q and remainder r where a = b × q + r. All basic arithmetic (sum, difference, product) is computed alongside. Results appear on a number line.
Formula
How this is calculated
The greatest common divisor (GCD) of two integers is the largest positive integer that divides both without leaving a remainder. The fastest method is the Euclidean algorithm: repeatedly replace the larger number with the remainder of dividing by the smaller, until the remainder is zero. For example, GCD(48, 18): 48 = 18 × 2 + 12, then 18 = 12 × 1 + 6, then 12 = 6 × 2 + 0, so GCD = 6. The algorithm runs in O(log min(a, b)) steps.
The least common multiple (LCM) is the smallest positive integer that is a multiple of both numbers. Rather than listing multiples, compute it from the GCD: LCM(a, b) = |a × b| / GCD(a, b). This works because GCD × LCM = |a × b| for any pair of integers.
Integer division (quotient and remainder) satisfies the division algorithm: a = b × q + r, where 0 ≤ |r| < |b|. JavaScript's Math.trunc() implements truncated division (remainder has the same sign as the dividend), which is what this calculator uses. The GCD and LCM are always non-negative by convention, and GCD(0, n) = n for any non-zero n.
Frequently asked questions
It uses the fact that GCD(a, b) = GCD(b, a mod b). Starting with the two numbers, repeatedly replace the larger with the remainder of dividing by the smaller, until the remainder is zero. The last non-zero remainder is the GCD. For example, GCD(252, 105): 252 mod 105 = 42, then 105 mod 42 = 21, then 42 mod 21 = 0, so GCD = 21.
LCM is essential for adding fractions with different denominators (find the LCM of the denominators as the common denominator), scheduling repeating events (if event A repeats every a days and B every b days, they next coincide after LCM(a, b) days), and synchronising periodic processes in music, computing and engineering.
GCD and LCM are defined as positive, so this calculator uses the absolute values of both inputs. The quotient and remainder follow JavaScript's truncated division: -7 ÷ 3 gives quotient -2 and remainder -1, since -7 = 3 × (−2) + (−1).
Also known as
TG we-Calculate Editorial Team. (2026). Integer Calculator — GCD, LCM, Division & Arithmetic [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/integer-calculator
TG we-Calculate Editorial Team. "Integer Calculator — GCD, LCM, Division & Arithmetic." TG we-Calculate. 2026. https://we-calculate.com/calculator/integer-calculator.
TG we-Calculate Editorial Team, "Integer Calculator — GCD, LCM, Division & Arithmetic," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/integer-calculator
@misc{wecalculate_integer_calculator, title = {Integer Calculator — GCD, LCM, Division & Arithmetic}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/integer-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
