CSEC3616Cybersecurity Engineering

    Divisibility and the greatest common divisor

    Divisibility notation and properties, the division algorithm, and the Euclidean algorithm for computing a greatest common divisor.

    • State the four basic properties of divisibility, including transitivity and the linear-combination property.
    • Apply the division algorithm to write any integer as a=qn+r with 0<=r<n.
    • Compute gcd(a, b) by hand using the Euclidean algorithm.

    12 min read

    Intuition

    Every later idea in this module rests on one question: does one number split evenly into another? RSA key generation depends on it directly — an encryption exponent ee only has a working decryption partner dd because gcd(e,φ(n))=1\gcd(e, \varphi(n)) = 1. Diffie-Hellman, modular inverses, and the extended Euclidean algorithm on the next page all start from the same machinery covered here: divisibility and the greatest common divisor.

    Mechanism

    A non-zero integer bb divides aa if a=mba = mb for some integer mm — dividing aa by bb leaves no remainder. This is written bab \mid a, and bb is called a divisor of aa. For example, 1318213 \mid 182 because 182=14×13182 = 14 \times 13, and 1728917 \mid 289 because 289=17×17289 = 17 \times 17.

    Four properties follow directly from the definition:

    • If a1a \mid 1, then a=±1a = \pm 1.
    • If aba \mid b and bab \mid a, then a=±ba = \pm b.
    • Any b0b \neq 0 divides 00.
    • Transitivity: if aba \mid b and bcb \mid c, then aca \mid c.

    Transitivity holds because aba \mid b and bcb \mid c mean b=amb = am and c=bnc = bn for some integers m,nm, n. Substituting the first into the second gives c=amnc = amn, so aca \mid c. The lecture gives two instances of this: 393 \mid 9 and 9279 \mid 27 give 3273 \mid 27; 116611 \mid 66 and 6619866 \mid 198 give 1119811 \mid 198.

    A stronger property extends this to combinations. If bgb \mid g and bhb \mid h, then bb divides mg+nhmg + nh for any integers mm and nn — not just g+hg + h or ghg - h. This is the linear combination property. The lecture’s example: 116611 \mid 66 and 117711 \mid 77, so 1111 divides m66+n77m \cdot 66 + n \cdot 77 for any m,nm, n. Writing 66=11k66 = 11k and 77=11l77 = 11l, m66+n77=m11k+n11l=11(mk+nl),m \cdot 66 + n \cdot 77 = m \cdot 11k + n \cdot 11l = 11(mk + nl), which is a multiple of 1111 regardless of what mm and nn are.

    The division algorithm formalises ordinary long division. For a positive integer nn and a non-negative integer aa, a=qn+r,0r<n,q=an.a = qn + r, \quad 0 \le r < n, \quad q = \left\lfloor \frac{a}{n} \right\rfloor. qq is the quotient, rr is the remainder, and \lfloor \cdot \rfloor is the floor function: the greatest integer no larger than the argument. The remainder is always non-negative and strictly less than nn — this constraint is what makes qq and rr unique for a given aa and nn.

    The greatest common divisor of aa and bb, gcd(a,b)\gcd(a, b), is the largest integer that divides both. Equivalently, gcd(a,b)=max{k:ka and kb}\gcd(a, b) = \max\{k : k \mid a \text{ and } k \mid b\}. Because the definition requires a positive result, gcd(a,b)=gcd(a,b)\gcd(a, b) = \gcd(|a|, |b|) — sign does not matter. gcd(a,0)=a\gcd(a, 0) = |a| since every integer divides 00, and gcd(0,0)\gcd(0, 0) is defined to be 00. Two integers are relatively prime if their only common positive divisor is 11, equivalently gcd(a,b)=1\gcd(a, b) = 1.

    The Euclidean algorithm finds gcd(a,b)\gcd(a, b) by repeated application of the division algorithm: replace (a,b)(a, b) with (b,amodb)(b, a \bmod b) and repeat until the remainder is 00. The last non-zero remainder is the gcd. Each step is smaller than the last, so the algorithm always terminates.

    Worked example

    Answergcd(710, 310) = 10

    The lecture names this exact example, but the figure showing its working did not survive extraction from the source PDF. The steps below apply the division algorithm repeatedly, exactly as defined above.

    1. 710=2×310+90710 = 2 \times 310 + 90 — divide 710 by 310, quotient 2, remainder 90.
    2. 310=3×90+40310 = 3 \times 90 + 40 — repeat on (310, 90).
    3. 90=2×40+1090 = 2 \times 40 + 10 — repeat on (90, 40).
    4. 40=4×10+040 = 4 \times 10 + 0 — the remainder is 0, so the algorithm stops.
    5. The last non-zero remainder was 1010, so gcd(710,310)=10\gcd(710, 310) = 10.

    Exam detail

    Relatively prime means the only common positive divisor is 11 — neither number has to be prime itself. 88 and 1515 are relatively prime: the divisors of 88 are 1,2,4,81, 2, 4, 8 and the divisors of 1515 are 1,3,5,151, 3, 5, 15, and 11 is the only entry on both lists.

    Two edge cases are worth having ready: gcd(a,0)=a\gcd(a, 0) = |a|, and gcd(0,0)=0\gcd(0, 0) = 0 by definition. Both follow from “any non-zero bb divides 00” — 00 places no constraint on a common divisor, so the largest one is whatever aa contributes.

    Formula

    Division algorithm

    a=qn+r,0r<n,q=ana = qn + r, \quad 0 \le r < n, \quad q = \left\lfloor \frac{a}{n} \right\rfloor
    aa
    the dividend
    nn
    the divisor (positive)
    qq
    the quotient
    rr
    the remainder, 0 <= r < n

    Pitfall

    q=a/nq = \lfloor a/n \rfloor, not a/na/n rounded or truncated toward zero — for non-negative aa and positive nn these agree, but do not carry the habit of “round toward zero” into modular arithmetic on the next page, where negative dividends make the two rules disagree.

    Recall

    Why does 11 | 66 and 11 | 77 guarantee 11 divides m·66 + n·77 for every integer m and n?

    Because 66=11k66 = 11k and 77=11l77 = 11l for some integers k,lk, l. Substituting, m66+n77=11(mk+nl)m \cdot 66 + n \cdot 77 = 11(mk + nl), which is 1111 times an integer — so 1111 divides it, whatever mm and nn are.