6 Number Theory And Modular Arithmetic

Discrete Structure · Unit 6

Number Theory and Modular Arithmetic

Exam-focused notes for Number Theory and Modular Arithmetic (Discrete Structure, BIT152): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.

Number Theory and Modular Arithmetic in short

Number theory studies the properties of integers. Its ideas, such as gcd, modular arithmetic and primes, are the base of hashing, check digits and modern encryption.

Number Theory and Modular Arithmetic: notes

Divisibility and division algorithm

An integer $a$ divides an integer $b$ ($a \mid b$) if $b = ac$ for some integer $c$, where $a \ne 0$. We say $a$ is a factor (divisor) of $b$, and $b$ is a multiple of $a$.

Properties for integers $a, b, c$:

  • If $a \mid b$ and $a \mid c$, then $a \mid (b + c)$.
  • If $a \mid b$, then $a \mid bc$ for any integer $c$.
  • If $a \mid b$ and $b \mid c$, then $a \mid c$.

Division algorithm. For an integer $a$ and a positive integer $d$, there are unique integers $q$ and $r$ with:

$$a = dq + r, \qquad 0 \le r < d$$

Here $d$ is the divisor, $q$ the quotient ($q = \lfloor a/d \rfloor$) and $r$ the remainder ($r = a \bmod d$).

Example. $a = 47$, $d = 6$: $47 = 6 \cdot 7 + 5$, so $q = 7$, $r = 5$.

Example. $a = -17$, $d = 5$: $-17 = 5 \cdot (-4) + 3$, so $q = -4$ and $r = 3$. The remainder is never negative.

Greatest common divisor

The greatest common divisor $\gcd(a, b)$ is the largest integer that divides both $a$ and $b$. If $\gcd(a, b) = 1$, the numbers are relatively prime (coprime). The least common multiple $\operatorname{lcm}(a, b)$ is the smallest positive integer divisible by both.

Example. The divisors of 24 are 1, 2, 3, 4, 6, 8, 12, 24. The divisors of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36. The common ones are 1, 2, 3, 4, 6, 12, so $\gcd(24, 36) = 12$.

Using prime factorization: $24 = 2^3 \cdot 3$ and $36 = 2^2 \cdot 3^2$. The gcd takes the smaller power of each prime: $2^2 \cdot 3 = 12$. The lcm takes the larger power: $2^3 \cdot 3^2 = 72$. Also $\gcd(a, b) \cdot \operatorname{lcm}(a, b) = ab$. Check: $12 \cdot 72 = 864 = 24 \cdot 36$.

Euclidean algorithm

Finding the gcd by listing factors is slow for big numbers. The Euclidean algorithm uses the fact that $\gcd(a, b) = \gcd(b, a \bmod b)$. Divide repeatedly until the remainder is 0. The last non-zero remainder is the gcd.

procedure gcd(a, b)
  while b != 0
    r = a mod b
    a = b
    b = r
  return a

Example. Find $\gcd(252, 198)$.

$$\begin{aligned} 252 &= 1 \cdot 198 + 54 \ 198 &= 3 \cdot 54 + 36 \ 54 &= 1 \cdot 36 + 18 \ 36 &= 2 \cdot 18 + 0 \end{aligned}$$

The last non-zero remainder is 18, so $\gcd(252, 198) = 18$.

Example. Find $\gcd(101, 37)$.

$$\begin{aligned} 101 &= 2 \cdot 37 + 27 \ 37 &= 1 \cdot 27 + 10 \ 27 &= 2 \cdot 10 + 7 \ 10 &= 1 \cdot 7 + 3 \ 7 &= 2 \cdot 3 + 1 \ 3 &= 3 \cdot 1 + 0 \end{aligned}$$

The gcd is 1, so they are relatively prime.

What this unit covers

  • Divisibility and division algorithm
  • Greatest common divisor
  • Euclidean algorithm
  • Extended Euclidean algorithm
  • Congruence modulo
  • Arithmetic modulo m
  • Multiplicative inverse
  • Chinese Remainder Theorem
  • Prime numbers and trial division

Chinese Remainder Theorem

2082 · 10 marks

State division theory.Add two integers 13578 and 45730 using Chinese Remainder Theorem.[2+8]

Show solved answer

Division Theory and Chinese Remainder Theorem


Part 1: Division Theory (2 marks)

Division Algorithm (Division Theory):

For any integer $a$ and any positive integer $n$, there exist unique integers $q$ (quotient) and $r$ (remainder) such that:

$$a = q \cdot n + r, \qquad 0 \leq r < n$$

where $q = \lfloor a/n \rfloor$ and $r = a \bmod n$.


Part 2: Adding 13578 + 45730 using CRT (8 marks)

The idea of CRT-based arithmetic: pick pairwise coprime moduli whose product exceeds the answer, reduce each operand mod each modulus, add residue-wise, then reconstruct.

Step 1: Choose pairwise coprime moduli

Expected result: $$13578 + 45730 = 59308$$

Choose: $$m_1 = 99,\quad m_2 = 98,\quad m_3 = 97,\quad m_4 = 95$$

These are pairwise coprime, and $$M = 99 \times 98 \times 97 \times 95 = 89{,}403{,}930 \gg 59308 \checkmark$$

Step 2: Residue representation

For $a = 13578$:

  • $99 \times 137 = 13563 \Rightarrow 13578 - 13563 = 15$
  • $98 \times 138 = 13524 \Rightarrow 13578 - 13524 = 54$
  • $97 \times 139 = 13483 \Rightarrow 13578 - 13483 = 95$
  • $95 \times 142 = 13490 \Rightarrow 13578 - 13490 = 88$

$$a \to (15,\ 54,\ 95,\ 88)$$

For $b = 45730$:

  • $99 \times 461 = 45639 \Rightarrow 45730 - 45639 = 91$
  • $98 \times 466 = 45668 \Rightarrow 45730 - 45668 = 62$
  • $97 \times 471 = 45687 \Rightarrow 45730 - 45687 = 43$
  • $95 \times 481 = 45695 \Rightarrow 45730 - 45695 = 35$

$$b \to (91,\ 62,\ 43,\ 35)$$

(Note: $45730 \bmod 99 = 91$.)

Step 3: Add residues modulo each $m_i$

$$r_i = (a_i + b_i) \bmod m_i$$

Modulus$a_i + b_i$$r_i$
$99$$15 + 91 = 106$$106 - 99 = \mathbf{7}$
$98$$54 + 62 = 116$$116 - 98 = \mathbf{18}$
$97$$95 + 43 = 138$$138 - 97 = \mathbf{41}$
$95$$88 + 35 = 123$$123 - 95 = \mathbf{28}$

So the sum $X$ satisfies: $$X \equiv 7 \pmod{99},\quad X \equiv 18 \pmod{98},\quad X \equiv 41 \pmod{97},\quad X \equiv 28 \pmod{95}$$

Step 4: Verify against 59308

  • $99 \times 599 = 59301 \Rightarrow 59308 - 59301 = 7$ ✓
  • $98 \times 605 = 59290 \Rightarrow 59308 - 59290 = 18$ ✓
  • $97 \times 611 = 59267 \Rightarrow 59308 - 59267 = 41$ ✓
  • $95 \times 624 = 59280 \Rightarrow 59308 - 59280 = 28$ ✓

All four residues match, confirming the reconstructed value.

Final Answer

$$\boxed{13578 + 45730 = 59308}$$

represented in CRT residue form as $(7,\ 18,\ 41,\ 28)$ with respect to moduli $(99, 98, 97, 95)$.

Open this answer on its own page →

2080 · 5 marks

Solve the system of following congruences using Chinese Remainder theorem: x = 2 (mod 3), x = 3 (mod 5), x = 2 (mod 7) [5]

$$x \equiv 2 \pmod{3}, \quad x \equiv 3 \pmod{5}, \quad x \equiv 2 \pmod{7}$$ Remainders: $a1 = 2,\ a2 = 3,\ a3 = 2$ Moduli: $m1 = 3,\ m2 = 5,\ m3 = 7$ The moduli are pairwise coprime, so CRT guarantees a unique solution modulo their product. --- $$M = 3 \times 5 \times 7 = 105$$ --- $$M1 = \frac...

Open this answer on its own page →

2080.1 · 5 marks

How do you solve computer arithmetic with large integers using Chinese remainder theorem? Give an example. [5]

Modern computers have a fixed word size (e.g., 32-bit or 64-bit). When performing arithmetic on very large integers, the numbers may exceed the machine's word size, causing overflow. The Chinese Remainder Theorem (CRT) provides an elegant solution by breaking large integer arithmetic into several...

Open this answer on its own page →

Extended Euclidean algorithm

2081 · 5 marks

Find the multiplicative inverse of 6 in $\mathbb{Z}_{25}$ using Extended Euclidean Algorithm. [5]

  • Modulus: $n = 25$ - Element whose inverse is sought: $a = 6$ - Ring: $\mathbb{Z}{25}$ - Goal: find $x$ such that $6x \equiv 1 \pmod{25}$ $$25 = 4 \times 6 + 1$$ $$6 = 6 \times 1 + 0$$ So $\gcd(25, 6) = 1$. Since the gcd is $1$, the inverse exists. From the first equation, isolate the remainder ...
Open this answer on its own page →

Arithmetic modulo m

2081 · 5 marks

Compute the value of $8 \text{ MOD } 8$, $-9 \text{ MOD } 4$, $7 \text{ MOD } 17$, $6 \text{ MOD } 7$ and $-8 \text{ MOD } 3$. [5]

Expressions to evaluate: - $8 \bmod 8$ - $-9 \bmod 4$ - $7 \bmod 17$ - $6 \bmod 7$ - $-8 \bmod 3$ For integers $a$ and modulus $b 0$: $$a \bmod b = a - b \times \left\lfloor \frac{a}{b} \right\rfloor$$ This yields a result satisfying $0 \le (a \bmod b) < b$. --- $$\left\lfloor \frac{8}{8} \right...

Open this answer on its own page →

2079 · 5 marks

What is arithmetic modulo $m$? Use the definition of addition and multiplication in $\mathbb{Z}m$ to find $7 +{11} 9$ and $7 *_{11} 9$. [5]

Show solved answer

Given

Given data:

  • Modulus: $m = 11$
  • Set: $\mathbb{Z}_{11} = {0, 1, 2, \ldots, 10}$
  • Compute $7 +_{11} 9$
  • Compute $7 *_{11} 9$

All required data present.


Solution

Arithmetic Modulo m

Arithmetic modulo m is arithmetic carried out on the finite set

$$\mathbb{Z}_m = {0, 1, 2, \ldots, m-1}$$

where every result of addition or multiplication is replaced by its remainder upon division by $m$. This keeps all results within the set $\mathbb{Z}_m$ (closure).

Addition in $\mathbb{Z}_m$: $$a +_m b = (a + b) \bmod m$$

Multiplication in $\mathbb{Z}_m$: $$a *_m b = (a \cdot b) \bmod m$$


Compute $7 +_{11} 9$

$$7 +_{11} 9 = (7 + 9) \bmod 11 = 16 \bmod 11$$

Since $16 = 1 \times 11 + 5$:

$$7 +_{11} 9 = 5$$


Compute $7 *_{11} 9$

$$7 *_{11} 9 = (7 \times 9) \bmod 11 = 63 \bmod 11$$

Since $63 = 5 \times 11 + 8$:

$$7 *_{11} 9 = 8$$


Summary

OperationOrdinary result$\bmod 11$Answer
$7 +_{11} 9$$16$$16 \bmod 11$$\mathbf{5}$
$7 *_{11} 9$$63$$63 \bmod 11$$\mathbf{8}$
Open this answer on its own page →

Congruence modulo

2078 · 5 marks

What is congruent modulo? Determine whether 20 is congruent to 8 modulo 6 and 25 is congruent to 17 modulo 5. [5]

  • Check 1: Is $20 \equiv 8 \pmod{6}$? - Check 2: Is $25 \equiv 17 \pmod{5}$? Two integers $a$ and $b$ are congruent modulo $n$ (written $a \equiv b \pmod{n}$) if $n$ divides their difference: $$a \equiv b \pmod{n} \iff n \mid (a - b)$$ Equivalently, $a$ and $b$ leave the same remainder when divid...
Open this answer on its own page →

Prime numbers and trial division

2078 · 5 marks

Explain trial division with example? Using trial division, show that 101 is prime. [5]

  • Number to test: $n = 101$ - Method required: trial division - Marks: 5 Trial division is a primality-testing method. To determine whether an integer $n 1$ is prime, we attempt to divide $n$ by successive integers starting from $2$. If any of them divides $n$ exactly (remainder $0$), then $n$ is...
Open this answer on its own page →

Euclidean algorithm

0 · 5 marks

Explain Euclidean algorithm. Use Euclidean algorithm to find the greatest common divisor of 414 and 662. [5]

  • Two integers: $414$ and $662$. - Task: find $\gcd(414, 662)$ using the Euclidean algorithm. The Euclidean Algorithm finds the Greatest Common Divisor (GCD) of two integers using the division property: If $a = b \cdot q + r$ (where $0 \le r < b$), then $\gcd(a, b) = \gcd(b, r)$. Reason: Any comm...
Open this answer on its own page →