Difference between revisions of "Modular arithmetic"

(Introductory)
(Computation of Powers Mod n)
Line 35: Line 35:
 
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).
 
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).
  
By the "Multiplication" property above, then, it follows that
+
By the "multiplication" property above, then, it follows that
  
 
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).
 
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).

Revision as of 21:04, 24 June 2006

Modular arithmetic is a special type of arithmetic that involves only integers. Given integers $a$, $b$, and $n$, with $n > 0$, we say that $a$ is congruent to $b$ modulo $n$, or $a \equiv b$ (mod $n$), if the difference ${a - b}$ is divisible by $n$.

For a given positive integer $n$, the relation $a \equiv b$ (mod $n$) is an equivalence relation on the set of integers. This relation gives rise to an algebraic structure called the integers modulo $n$ (usually known as "the integers mod $n$," or $\mathbb{Z}_n$ for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to Diophantine equations, testing whether certain large numbers are prime, and even some problems in cryptology.


Introductory

Useful Facts

Consider four integers ${a},{b},{c},{d}$ and a positive integer ${m}$ such that $a\equiv b\pmod {m}$ and $c\equiv d\pmod {m}$. In modular arithmetic, the following identities hold:

  • Addition: $a+c\equiv b+d\pmod {m}$.
  • Substraction: $a-c\equiv b-d\pmod {m}$.
  • Multiplication: $ac\equiv bd\pmod {m}$.
  • Division: $\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}$, where $e$ is a positive integer that divides ${a}$ and $b$.
  • Exponentiation: $a^e\equiv b^e\pmod {m}$ where $e$ is a positive integer.

Examples

  • ${7}\equiv {1} \pmod {2}$
  • $49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}$
  • $7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}$

Computation of Powers Mod n

The "exponentiation" property given above allows us to perform rapid calculations modulo $n$. Consider, for example, the problem

What are the tens and units digits of $7^{1942}$?

We could (in theory) solve this problem by trying to compute $7^{1942}$, but this would be extremely time-consuming. Moreover, it would give us much more information than we need. Since we want only the tens and units digits of the number in question, it suffices to find the remainder when the number is divided by $100$. In other words, all of the information we need can be found using arithmetic mod $100$.

By writing down the first few powers of $7$, we see that $7^4 = 2401 \equiv 1$ (mod $100$). So for any positive integer $k$, we have $7^{4k} = (7^4)^k \equiv 1^k \equiv 1$ (mod $100$). In particular, we can write

$7^{1940} = 7^{4 \cdot 485} \equiv 1$ (mod $100$).

By the "multiplication" property above, then, it follows that

$7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49$ (mod $100$).

Therefore, by the definition of congruence, $7^{1942}$ differs from $49$ by a multiple of $100$. Since both integers are positive, this means that they share the same tens and units digits. Those digits are $4$ and $9$, respectively.

Applications

Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve Linear Diophantine equations, and it often helps with other Diophantine equations as well.

Intermediate

Topics

See also

Miscellany

The binary operation "mod"

Related to the concept of congruence mod $n$ is the binary operation $a$ mod $n$, which is used often in computer programming.

Recall that, by the Division Algorithm, given any two integers $a$ and $n$, with $n > 0$, we can find integers $q$ and $r$, with $0 \leq r < n$, such that $a = nq + r$. The number $q$ is called the quotient, and the number $r$ is called the remainder. The operation $a$ mod $n$ returns the value of the remainder $r$. For example:

$15$ mod $6 = 3$, since $15 = 6 \cdot 2 + 3$.

$35$ mod $7 = 0$, since $35 = 7 \cdot 5 + 0$.

$-10$ mod $8 = 6$, since $-10 = 8 \cdot -2 + 6$.

Observe that if $a$ mod $n = r$, then we also have $a \equiv r$ (mod $n$).