maths.freeNumber Theory › GCD and LCM

GCD and LCM

Euclid's algorithm and the identity gcd × lcm = a × b.

The greatest common divisor is found without factoring at all: replace the larger number by the remainder when it is divided by the smaller, repeat, and the last non-zero remainder is the gcd. That is Euclid's algorithm, 2,300 years old and still what your computer uses. The lcm follows from gcd × lcm = a × b.

ნამდვილი ასლი: gcd(48, 18)

Gcd(48, 18)

48,\ 18

ჟრყოკა ოჲ ჟრყოკა.

  1. \gcd(48, 18)

    Use Euclid's algorithm: replace the larger number by its remainder on division by the smaller, until the remainder is 0.

  2. 48 = 2 \times 18 + 12

    Divide 48 by 18: quotient 2, remainder 12.

  3. 18 = 1 \times 12 + 6

    Divide 18 by 12: quotient 1, remainder 6.

  4. 12 = 2 \times 6 + 0

    Divide 12 by 6: quotient 2, remainder 0.

  5. \gcd(48, 18) = 6

    The last non-zero remainder is 6.

ჲრკპთირვ ჲრდჲგჲპა.
\gcd(48, 18) = 6

Symbols used here

a \mid b,\ \gcd(a,b)
divides, greatest common divisor
b is a multiple of a; the largest number dividing both.
\log_b x,\ \ln x
logarithm, natural log
The exponent b must be raised to for x; ln uses base e.
\sum_{k=1}^{n} a_k
summation
Add a_k for k = 1 up to n.
\prod_{k=1}^{n} a_k
product
Multiply a_k for k = 1 up to n.
\mathbb{N},\ \mathbb{Z},\ \mathbb{Q},\ \mathbb{R},\ \mathbb{C}
number sets
Naturals, integers, rationals, reals, complex numbers.
a \equiv b \pmod n
congruent modulo n
n divides a − b; a and b have the same remainder.
\varphi(n),\ \pi(x)
Euler's totient, prime-counting function
Count of 1..n coprime to n; number of primes up to x.
\mathbb{Z}/n\mathbb{Z},\ \mathbb{Z}_n
integers modulo n
The remainders 0…n−1 with clock arithmetic.
a \bmod n
remainder
What is left after dividing a by n.

How to: GCD and LCM

  1. Use Euclid's algorithm: replace the larger number by its remainder on division by the smaller, until the remainder is 0.
  2. Divide 48 by 18: quotient 2, remainder 12.
  3. Divide 18 by 12: quotient 1, remainder 6.
  4. Divide 12 by 6: quotient 2, remainder 0.
  5. The last non-zero remainder is 6.

Questions people ask

Why are primes so important?

Every integer factors into primes in exactly one way, so primes are the atoms of multiplication. Cryptography relies on that factoring being easy to state and hard to do.

How do I tell whether a big number is prime?

Trial division up to the square root works for small numbers. For large ones, probabilistic tests (Miller–Rabin) give an answer that is wrong with negligible probability, and deterministic tests (AKS) exist but are slower.

ჲოთრაი ჟამ.

მეტი Number Theory