Skip to content
/ Graphing calculator / GCD, LCM and number theory

GCD, LCM and number theory

GCD and LCM of several integers with the steps of Euclid's algorithm, prime factorization, divisors, primality test, Euclidean division, Bézout's identity and the equation ax + by = c, aⁿ modulo m, modular inverse and the congruence ax ≡ b (mod m): school and first-year number theory, with integers of any size.

Frequently asked questions

How do you find the GCD with Euclid's algorithm?

Divide the larger number by the smaller, then the divisor by the remainder, and so on: the GCD is the last non-zero remainder. For 1071 and 462: 1071 = 462 × 2 + 147, 462 = 147 × 3 + 21, 147 = 21 × 7 + 0, so gcd = 21. The LCM follows, since gcd × lcm = a × b: it is 23,562.

What is Bézout's identity used for?

Two integers a and b are coprime if and only if there are integers u and v with au + bv = 1 (Bézout's theorem). The extended Euclidean algorithm gives u and v; it is used to solve ax + by = c, to find an inverse modulo m and to solve ax ≡ b (mod m).

How large can the numbers be?

Calculations use exact integers of any size (up to a few thousand digits). Prime factorization is limited to 60 digits and a few seconds of computing; above 3.3 × 10²⁴, the primality of a factor comes from the Miller-Rabin test, which gives practical certainty rather than a proof.

More calculator pages

How to use it

  1. GCD and LCM: type two or more integers separated by “;” or spaces. For two numbers, the steps of Euclid's algorithm are shown, and the prime-factor method when they have fewer than 18 digits.
  2. Factors and divisors: n as a product of primes, number of divisors, their sum, Euler's totient φ(n) and the list of divisors; the test says whether n is prime.
  3. Euclidean division: a = bq + r with 0 ≤ r < |b|, including for a negative dividend.
  4. Bézout: the extended Euclidean table, the coefficients u and v and, if you give c, every integer solution of ax + by = c.
  5. Congruences: aⁿ modulo m with the period of the remainders, inverse of a modulo m, the equation ax ≡ b (mod m).

Every field accepts an integer calculation: 2^61-1, 20!+1, 3*(7+2).

Examples

See also the binary and hex converter and the full graphing calculator.

Guide written and checked by the Otoolia team · updated 25 November 2026.