Number TheoryTopic #30 of 40

Divisibility

Division algorithm, divisibility rules, GCD, LCM, and the Euclidean algorithm.

Definition

An integer aa divides an integer bb (written a∣ba \mid b) if there exists an integer kk such that: b=akb = ak

We say aa is a divisor or factor of bb, and bb is a multiple of aa.

If a∤ba \nmid b, then aa does not divide bb.

Basic Properties

For all integers a,b,ca, b, c:

  1. a∣0a \mid 0 (every integer divides 0)
  2. 1∣a1 \mid a (1 divides every integer)
  3. If a∣ba \mid b and b∣cb \mid c, then a∣ca \mid c (transitivity)
  4. If a∣ba \mid b and a∣ca \mid c, then a∣(b+c)a \mid (b + c) and a∣(b−c)a \mid (b - c)
  5. If a∣ba \mid b, then a∣bca \mid bc for any integer cc
  6. If a∣ba \mid b and a∣ca \mid c, then a∣(mb+nc)a \mid (mb + nc) for any integers m,nm, n

For positive integers:

If a∣ba \mid b and b≠0b \neq 0, then ∣a∣≤∣b∣|a| \leq |b|.

Division Algorithm

For any integers aa and dd with d>0d > 0, there exist unique integers qq (quotient) and rr (remainder) such that: a=dq+rwhere 0≤r<da = dq + r \quad \text{where } 0 \leq r < d

Notation

  • a÷d=qa \div d = q (integer division)
  • amod  d=ra \mod d = r (remainder)

Examples

  • 17=5×3+217 = 5 \times 3 + 2, so 17÷5=317 \div 5 = 3 and 17mod  5=217 \mod 5 = 2
  • −17=5×(−4)+3-17 = 5 \times (-4) + 3, so −17÷5=−4-17 \div 5 = -4 and −17mod  5=3-17 \mod 5 = 3

Greatest Common Divisor (GCD)

The greatest common divisor of aa and bb, written gcd⁡(a,b)\gcd(a, b) or (a,b)(a, b), is the largest positive integer that divides both.

Properties

gcd⁡(a,b)=gcd⁡(b,a)\gcd(a, b) = \gcd(b, a) gcd⁡(a,0)=∣a∣\gcd(a, 0) = |a| gcd⁡(a,b)=gcd⁡(a−b,b)=gcd⁡(amod  b,b)\gcd(a, b) = \gcd(a - b, b) = \gcd(a \mod b, b) gcd⁡(a,b)=gcd⁡(a,b−a)\gcd(a, b) = \gcd(a, b - a)

Coprime (Relatively Prime)

aa and bb are coprime if gcd⁡(a,b)=1\gcd(a, b) = 1.

Euclidean Algorithm

Efficiently computes gcd⁡(a,b)\gcd(a, b) using repeated division.

Algorithm

gcd(a, b):
    while b ≠ 0:
        r = a mod b
        a = b
        b = r
    return a

Example

gcd⁡(252,105)\gcd(252, 105) 252=105×2+42252 = 105 \times 2 + 42 105=42×2+21105 = 42 \times 2 + 21 42=21×2+042 = 21 \times 2 + 0

gcd⁡(252,105)=21\gcd(252, 105) = 21

Time Complexity

O(log⁡(min⁡(a,b)))O(\log(\min(a, b))) divisions

Extended Euclidean Algorithm

Finds integers xx and yy such that: gcd⁡(a,b)=ax+by\gcd(a, b) = ax + by

Bézout's Identity

For any integers aa and bb (not both zero), there exist integers xx and yy such that: gcd⁡(a,b)=ax+by\gcd(a, b) = ax + by

Example

Find x,yx, y such that gcd⁡(252,105)=252x+105y\gcd(252, 105) = 252x + 105y

Working backwards: 21=105−42×221 = 105 - 42 \times 2 21=105−(252−105×2)×221 = 105 - (252 - 105 \times 2) \times 2 21=105×5−252×221 = 105 \times 5 - 252 \times 2 21=252×(−2)+105×521 = 252 \times (-2) + 105 \times 5

So x=−2x = -2, y=5y = 5.

Least Common Multiple (LCM)

The least common multiple of aa and bb, written lcm(a,b)\text{lcm}(a, b) or [a,b][a, b], is the smallest positive integer divisible by both.

Relationship to GCD

gcd⁡(a,b)×lcm(a,b)=∣ab∣\gcd(a, b) \times \text{lcm}(a, b) = |ab|

lcm(a,b)=∣ab∣gcd⁡(a,b)\text{lcm}(a, b) = \frac{|ab|}{\gcd(a, b)}

Properties

lcm(a,b)=lcm(b,a)\text{lcm}(a, b) = \text{lcm}(b, a) lcm(a,1)=∣a∣\text{lcm}(a, 1) = |a| lcm(a,a)=∣a∣\text{lcm}(a, a) = |a|

Divisibility Rules

DivisorRule
2Last digit is even
3Sum of digits divisible by 3
4Last two digits form number divisible by 4
5Last digit is 0 or 5
6Divisible by both 2 and 3
8Last three digits divisible by 8
9Sum of digits divisible by 9
10Last digit is 0
11Alternating sum of digits divisible by 11

Linear Diophantine Equations

Equation of the form: ax+by=cax + by = c

Solvability

Has integer solutions if and only if gcd⁡(a,b)∣c\gcd(a, b) \mid c.

Finding Solutions

  1. Find particular solution (x0,y0)(x_0, y_0) using extended Euclidean algorithm
  2. General solution: x=x0+bdt,y=y0−adtx = x_0 + \frac{b}{d}t, \quad y = y_0 - \frac{a}{d}t where d=gcd⁡(a,b)d = \gcd(a, b) and t∈Zt \in \mathbb{Z}.