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
- Graphing calculator (every tab: exact calculations, functions, equations, sequences, statistics, probability, matrices, Python…)
- Limit calculator
- Inequality solver
- Binary, hex and decimal converter
- Equation solver
- Sequence calculator
- Statistics and regression
- Probability distributions
- Matrix calculator
- Symbolic algebra (CAS)
- Online Python (NumWorks, TI, Casio)
How to use it
- 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.
- 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.
- Euclidean division: a = bq + r with 0 ≤ r < |b|, including for a negative dividend.
- Bézout: the extended Euclidean table, the coefficients u and v and, if you give c, every integer solution of ax + by = c.
- 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
- gcd(1071, 462) = 21 and lcm = 23,562.
- 360 = 2³ × 3² × 5: (3 + 1)(2 + 1)(1 + 1) = 24 divisors.
- Bézout: 240 × (−9) + 46 × 47 = 2 = gcd(240, 46).
- 2026 = 17 × 119 + 3: dividing 2026 by 17 leaves 3.
- The remainders of 7ᵏ modulo 13 repeat every 12 steps; 2026 = 12 × 168 + 10, so 7²⁰²⁶ ≡ 7¹⁰ ≡ 4 (mod 13).
- The inverse of 3 modulo 7 is 5, because 3 × 5 = 15 ≡ 1 (mod 7).
See also the binary and hex converter and the full graphing calculator.
Guide written and checked by the Otoolia team · updated 25 November 2026.