Wilson’s theorem and related problems in Elementary Number Theory for RMO

I) Prove Wilson’s Theorem:

If p is a prime, then (p-1)! \equiv -1 {\pmod p}.


The cases for primes 2 and 3 are clearly true.

Assume p>3

Suppose that a is any one of the p-1 positive integers 1,2,3, \ldots {p-1} and consider the linear congruence
ax \equiv 1 {\pmod p}. Then, gcd(a,p)=1.

Now, apply the following theorem: the linear congruence ax \equiv b {\pmod n} has a solution if and only if d|b, where d = gcd(a,b). If d|b, then it has d mutually incongruent solutions modulo n.

So, by the above theorem, the congruence here admits a unique solution modulo p; hence, there is a unique integer a^{'}, with 1 \leq a^{'} \leq p-1, satisfying aa^{'} \equiv 1 {\pmod p}.

Because p is prime, a = a^{'} if and only if a=1 or a=p-1. Indeed, the congruence a^{2} \equiv 1 {\pmod p} is equivalent to (a-1)(a+1) \equiv 0 {\pmod p}. Therefore, either a-1 \equiv 0 {\pmod p}, in which case a=1, or a+1 \equiv 0 {\pmod p}, in which case a=p-1.

If we omit the numbers 1 and p-1, the effect is to group the remaining integers 2,3, \ldots (p-2) into pairs a and a^{'}, where a \neq a^{'}, such that the product aa^{'} \equiv 1 {\pmod p}. When these (p-3)/2 congruences are multiplied together and the factors rearranged, we get

2.3. \ldots (p-2) \equiv 1 {\pmod p}

or rather

(p-2)! \equiv 1 {\pmod p}

Now multiply by p-1 to obtain the congruence

(p-1)! \equiv p-1 \equiv -1 {\pmod p}, which was desired to be proved.

An example to clarify the proof of Wilson’s theorem:

Specifically, let us take prime p=13. It is possible to divide the integers 2,3,4, \ldots, 11 into (p-3)/2=5 pairs, each product of which is congruent to 1 modulo 13. Let us write out these congruences explicitly as shown below:

2.7 \equiv 1 {\pmod {13}}
3.9 \equiv 1 {\pmod {13}}
4.10 \equiv 1 {\pmod {13}}
5.8 \equiv 1 {\pmod {13}}
6.11 \equiv 1 {\pmod {13}}

Multpilying these congruences gives the result 11! = (2.7)(3.9)(4.10)(5.8)(6.11) \equiv 1 {\pmod {13}}

and as 12! \equiv 12 \equiv -1 {\pmod {13}}

Thus, (p-1)! \equiv -1 {\pmod p} with prime p=13.


The converse to Wilson’s theorem is also true. If (n-1)! \equiv -1 {\pmod n}, then n must be prime. For, if n is not a prime, then n has a divisor d with 1 1 is prime if and only if (n-1)! \equiv -1 {\pmod n}. Unfortunately, this test is of more theoretical than practical interest because as n increases, (n-1)! rapidly becomes unmanageable in size.

Let us illustrate an application of Wilson’s theorem to the study of quadratic congruences{ What we mean by quadratic congruence is a congruence of the form ax^{2}+bx+c \equiv 0 {\pmod n}, with a \not\equiv 0 {\pmod n} }

Theorem: The quadratic congruence x^{2}+1 \equiv 0 {\pmod p}, where p is an odd prime, has a solution if and only if p \equiv 1 {\mod 4}.


Let a be any solution of x^{2}+1 \equiv 0 {\pmod p} so that a^{2} \equiv -1 {\pmod p}. Because p \not |a, the outcome of applying Fermat’s Little Theorem is

1 \equiv a^{p-1} \equiv (a^{2})^{(p-1)/2} \equiv (-1)^{(p-1)/2} {\pmod p}

The possibility that p=4k+3 for some k does not arise. If it did, we would have

(-1)^{(p-1)/2} = (-1)^{2k+1} = -1

Hence, 1 \equiv -1 {\pmod p}. The net result of this is that p|2, which is clearly false. Therefore, p must be of the form 4k+1.

Now, for the opposite direction. In the product

(p-1)! = 1.2 \ldots \frac{p-1}{2} \frac{p+1}{2} \ldots (p-2)(p-1)

we have the congruences

p-1 \equiv -1 {\pmod p}
p-2 \equiv -2 {\pmod p}
p-3 \equiv -3 {\pmod p}
\frac{p+1}{2} \equiv - \frac{p-1}{2} {\pmod p}

Rearranging the factors produces
(p-1)! \equiv 1.(-1).2.(-2) \ldots \frac{p-1}{2}. (-\frac{p-1}{2}) {\pmod p} \equiv (-1)^{(p-1)/2}(.2. \ldots \frac{p-1}{2})^{2}{\pmod p}

because there are (p-1)/2 minus signs involved. It is at this point that Wilson’s theorem can be brought to bear; for, (p-1)! \equiv -1 {\pmod p}, hence,

-1 \equiv (-1)^{(p-1)/2}((\frac{p-1}{2})!)^{2} {\pmod p}

If we assume that p is of the form 4k+1, then (-1)^{(p-1)/2} =1, leaving us with the congruence

-1 \equiv (-\frac{p-1}{2})^{2}{\pmod p}.

The conclusion is that the integer (\frac{p-1}{2})! satisfies the quadratic congruence x^{2}+1 \equiv 0 {\pmod p}.

Let us take a look at an actual example, say, the case p=13, which is a prime of the form 4k+1. Here, we have \frac{p-1}{2}=6, and it is easy to see that 6! = 720 \equiv 5 {\pmod {13}} and 5^{2}+1 = 26 \equiv 0 {\pmod {13}}.

Thus, the assertion that ((p-1)!)^{2}+1 \equiv 0 {\pmod p} is correct for p=13.

Wilson’s theorem implies that there exists an infinitude of composite numbers of the form n!+1. On the other hand, it is an open question whether n!+1 is prime for infinitely many values of n. Refer, for example:


More later! Happy churnings of number theory!
Nalin Pithwa

Eight digit bank identification number and other problems of elementary number theory

Question 1:

Consider the eight-digit bank identification number a_{1}a_{2}\ldots a_{8}, which is followed by a ninth check digit a_{9} chosen to satisfy the congruence

a_{9} \equiv 7a_{1} + 3a_{2} + 9a_{3} + 7a_{4} + 3a_{5} + 9a_{6} + 7a_{7} + 3a_{8} {\pmod {10}}

(a) Obtain the check digits that should be appended to the two numbers 55382006 and 81372439.

(b) The bank identification number 237a_{4}18538 has an illegitimate fourth digit. Determine the value of the obscured digit.

Question 2:

(a) Find an integer having the remainders 1,2,5,5 when divided by 2, 3, 6, 12 respectively (Yih-hing, died 717)

(b) Find an integer having the remainders 2,3,4,5 when divided by 3,4,5,6 respectively (Bhaskara, born 1114)

(c) Find an integer having remainders 3,11,15 when divided by 10, 13, 17, respectively (Regiomontanus, 1436-1476)

Question 3:

Question 3:

Let t_{n} denote the nth triangular number. For which values of n does t_{n} divide t_{1}^{2} + t_{2}^{2} + \ldots + t_{n}^{2}

Hint: Because t_{1}^{2}+t_{2}^{2}+ \ldots + t_{n}^{2} = t_{n}(3n^{3}+12n^{2}+13n+2)/30, it suffices to determine those n satisfying 3n^{3}+12n^{2}+13n+2 \equiv 0 {\pmod {2.3.5}}

Question 4:

Find the solutions of the system of congruences:

3x + 4y \equiv 5 {\pmod {13}}
2x + 5y \equiv 7 {\pmod {13}}

Question 5:

Obtain the two incongruent solutions modulo 210 of the system

2x \equiv 3 {\pmod 5}
4x \equiv 2 {\pmod 6}
3x \equiv 2 {\pmod 7}

Question 6:

Use Fermat’s Little Theorem to verify that 17 divides 11^{104}+1

Question 7:

(a) If gcd(a,35)=1, show that a^{12} \equiv {\pmod {35}}. Hint: From Fermat’s Little Theorem, a^{6} \equiv 1 {\pmod 7} and a^{4} \equiv 1 {\pmod 5}

(b) If gcd(a,42) =1, show that 168=3.7.8 divides a^{6}-1
(c) If gcd(a,133)=gcd(b,133)=1, show that 133| a^{18} - b^{18}

Question 8:

Show that 561|2^{561}-1 and 561|3^{561}-3. Do there exist infinitely many composite numbers n with the property that n|2^{n}-2 and n|3^{n}-3?

Question 9:

Prove that any integer of the form n = (6k+1)(12k+1)(18k+1) is an absolute pseudoprime if all three factors are prime; hence, 1729=7.13.19 is an absolute pseudoprime.

Question 10:

Prove that the quadratic congruence x^{2}+1 \equiv 0 {\pmod p}, where p is an odd prime, has a solution if and only if p \equiv {pmod 4}.

Note: By quadratic congruence is meant a congruence of the form ax^{2}+bx+c \equiv 0 {\pmod n} with a \equiv 0 {\pmod n}. This is the content of the above proof.

More later,
Nalin Pithwa.

Elementary Number Theory, ISBN numbers and mathematics olympiads

Question 1:

The International Standard Book Number (ISBN) used in many libraries consists of nine digits a_{1} a_{2}\ldots a_{9} followed by a tenth check digit a_{10} (somewhat like Hamming codes), which satisfies

a_{10} = \sum_{k=1}^{9}k a_{k} \pmod {11}

Determine whether each of the ISBN’s below is correct.
(a) 0-07-232569-0 (USA)
(b) 91-7643-497-5 (Sweden)
(c) 1-56947-303-10 (UK)

Question 2:

When printing the ISBN a_{1}a_{2}\ldots a_{9}, two unequal digits were transposed. Show that the check digits detected this error.

Remark: Such codes are called error correcting codes and are fundamental to wireless communications including cell phone technologies.

More later,
Nalin Pithwa.

A good way to start mathematical studies …

I would strongly suggest to read the book “Men of Mathematics” by E. T. Bell.

It helps if you start at a young age. It doesn’t matter if you start later because time is relative!! 🙂

Well, I would recommend you start tinkering with mathematics by playing with nuggets of number theory, and later delving into number theory. An accessible way for anyone is “A Friendly Introduction to Number Theory” by Joseph H. Silverman. It includes some programming exercises also, which is sheer fun.

One of the other ways I motivate myself is to find out biographical or autobiographical sketches of mathematicians, including number theorists, of course. In this, the internet is an extremely useful information tool for anyone willing to learn…

Below is a list of some famous number theorists, and then there is a list of perhaps, not so famous number theorists — go ahead, use the internet and find out more about number theory, history of number theory, the tools and techniques of number theory, the personalities of number theorists, etc. Become a self-learner, self-propeller…if you develop a sharp focus, you can perhaps even learn from MIT OpenCourseWare, Department of Mathematics.

Famous Number Theorists (just my opinion);

1) Pythagoras
2) Euclid
3) Diophantus
4) Eratosthenes
5) P. L. Tchebycheff (also written as Chebychev or Chebyshev).
6) Leonhard Euler
7) Christian Goldbach
8) Lejeune Dirichlet
9) Pierre de Fermat
10) Carl Friedrich Gauss
11) R. D. Carmichael
12) Edward Waring
13) John Wilson
14) Joseph Louis Lagrange
15) Legendre
16) J. J. Sylvester
11) Leonoardo of Pisa aka Fibonacci.
15) Srinivasa Ramanujan
16) Godfrey H. Hardy
17) Leonard E. Dickson
18) Paul Erdos
19) Sir Andrew Wiles
20) George Polya
21) Sophie Germain
24) Niels Henrik Abel
25) Richard Dedekind
26) David Hilbert
27) Carl Jacobi
28) Leopold Kronecker
29) Marin Mersenne
30) Hermann Minkowski
31) Bernhard Riemann

Perhaps, not-so-famous number theorists (just my opinion):
1) Joseph Bertrand
2) Regiomontanus
3) K. Bogart
4) Richard Brualdi
5) V. Chvatal
6) J. Conway
7) R. P. Dilworth
8) Martin Gardner
9) R. Graham
10) M. Hall
11) Krishnaswami Alladi
12) F. Harary
13) P. Hilton
14) A. J. Hoffman
15) V. Klee
16) D. Kleiman
17) Donald Knuth
18) E. Lawler
19) A. Ralston
20) F. Roberts
21) Gian Carlo-Rota
22) Bruce Berndt
23) Richard Stanley
24) Alan Tucker
25) Enrico Bombieri

Happy discoveries lie on this journey…
-Nalin Pithwa.

Any integer can be written as the sum of the cubes of 5 integers, not necessarily distinct

Question: Prove that any integer can be written as the sum of the cubes of five integers, not necessarily.


We use the identity 6k = (k+1)^{3} + (k-1)^{3}- k^{3} - k^{3} for k=\frac{n^{3}-n}{6}=\frac{n(n-1)(n+1)}{6}, which is an integer for all n. We obtain

n^{3}-n = (\frac{n^{3}-n}{6}+1)^{3} + (\frac{n^{3}-n}{6}-1)^{3} - (\frac{n^{3}-n}{6})^{3} - (\frac{n^{3}-n}{6}).

Hence, n is equal to the sum

(-n)^{3} + (\frac{n^{3}-n}{6})^{3} + (\frac{n^{3}-n}{6})^{3} + (\frac{n-n^{3}}{6}-1)^{3}+ (\frac{n-n^{3}}{6}+1)^{3}.

More later,
Nalin Pithwa.

A random collection of number theory problems for RMO and CMI training

1) Find all prime numbers that divide 50!

2) If p and p^{2}+8 are both prime numbers, prove that p^{3}+4 is also prime.

3) (a) If p is a prime, and p \not|b, prove that in the AP a, a+b, a+2b, a+3b, \ldots, every pth term is divisible by p.

3) (b) From part a, conclude that if b is an odd integer, then every other term in the indicated progression is even.

4) Let p_{n} denote the nth prime. For n>5, show that p_{n}<p_{1}+p_{2}+ \ldots + p_{n-1}.

Hint: Use induction and Bertrand's conjecture.

5) Prove that for every n \geq 2, there exists a prime p with p \leq n < 2p.

More later,
Nalin Pithwa

Find the last two digits of 9^{9^{9}}

Here is a cute example of the power of theory of congruences. Monster numbers can be tamed !!

Question :

Find the last two digits of 9^{9^{9}}.


A famous mathematician, George Polya said that a good problem solving technique is to solve an analagous less difficult problem.

So, for example, if the problem posed was “find the last two digits of 2479”. How do we go about it? Find the remainder upon division by 100. Now, how does it relate to congruences ? Modulo 100 numbers !

So, the problem reduces to — find out 9^{9^{9}} \equiv 9 \pmod {10}.

Now, what is the stumbling block…the exponent 9^{9} makes the whole problem very ugly. But,

9^{9} \equiv 9 \pmod {10}, which means 9^{9}-9=10k, that is, 9^{9} = 9 + 10k,

also, use the fact 9^{9} \equiv 89 \pmod {100}

Hence, 9^{9^{9}}=9^{9+10k} = 9^{9}.9^{10k}

9^{9^{9}} \pmod {100}  = 9^{9}.9^{10k} \pmod {100} \equiv 89. 9^{10k} \pmod {100}

So, now we need to compute 9^{10k} \pmod {100} = (9^{10})^{k} \pmod {100} = (89.9)^{k} \pmod {100} = 89^{k}. 9^{k} \pmod {100}

Hence, 9^{9^{9}} \pmod {100} \equiv 89^{k+1}.9^{k} \pmod {100} \equiv (89.9)^{k}.89 \pmod {100} \equiv (1)^{k}.89 \pmod {100} \equiv 89 \pmod {100}.

-Nalin Pithwa.

A beautiful example of use of theory of congruences in engineering

The theory of congruences created by Gauss long ago is used in error control coding or error correction. The theory of congruences is frequently used to append an extra check digit to identification numbers, in order to recognize transmission errors or forgeries. Personal identification numbers of some kind appear in passports, credit cards, bank accounts, and a variety of other settings.

Some banks use (perhaps) an eight-digit identification number a_{1}a_{2}\ldots a_{8} together with a final check digit a_{0}. The check digit is usually obtained by multiplying the digits a_{i} for 1 \leq i \leq 8 by certain “weights” and calculating the sum of the weighted products modulo 10. For instance, the check digit might be chosen to satisfy:

a_{0} \equiv 7a_{1} + 3a_{2} + 9a_{3} + 7a_{4} + 3a_{5} + 9a_{6} + 7a_{7} + 3a_{8} {\pmod 10}

The identification number 815042169 would be printed on the cheque.

This weighting scheme for assigning cheque digits detects any single digit error in the identification number. For suppose that the digit a_{i} is replaced by a different a_{i}. By the manner in which the check digit is calculated, the difference between the correct a_{9} and the new a_9^{'} is

a_{9} - a_9^{'} \equiv k(a_{i} - a_{i}^{'}) \pmod {10}

where k is 7, 3, or 9 depending on the position of a_{i}^{'}. Because k(a_{i}-a_{i}^{'}) \not\equiv 0 \pmod {10}, it follows that a_{9} \neq a_{9}^{'} and the error is apparent. Thus, if the valid number 81504216 were incorrectly entered as 81504316 into a computer programmed to calculate check digits, an 8 would come up rather than the expected 9.

The modulo 10 approach is not entirely effective, for it does not always detect the common error of transposing distinct adjacent entries a and b within the string of digits. To illustrate, the identification numbers 81504216 and 81504261 have the same check digit 9 when our example weights are used. (The problem occurs when |a-b|=5). More sophisticated methods are available, with larger moduli and different weights, that would prevent this possible error.

-Nalin Pithwa.

How to find the number of proper divisors of an integer and other cute related questions

Question 1:

Find the number of proper divisors of 441000. (A proper divisor of a positive integer n is any divisor other than 1 and n):

Solution 1:

Any integer can be uniquely expressed as the product of powers of prime numbers (Fundamental theorem of arithmetic); thus, 441000 = (2^{3})(3^{2})(5^{3})(7^{2}). Any divisor, proper or improper, of the given number must be of the form (2^{a})(3^{b})(5^{c})(7^{d}) where 0 \leq a \leq 3, 0 \leq b \leq 2, 0 \leq c \leq 3, and 0 \leq d \leq 2. In this paradigm, the exponent a can be chosen in 4 ways, b in 3 ways, c in 4 ways, d in 3 ways. So, by the product rule, the total number of proper divisors will be (4)(3)(4)(3)-2=142.

Question 2:

Count the proper divisors of an integer N whose prime factorization is: N=p_{1}^{\alpha_{1}} p_{2}^{\alpha_{2}} p_{3}^{\alpha_{3}}\ldots p_{k}^{\alpha_{k}}

Solution 2:

By using the same reasoning as in previous question, the number of proper divisors of N is (\alpha_{1}+1)(\alpha_{2}+1)(\alpha_{3}+1)\ldots (\alpha_{k}+1)-2, where we deduct 2 because choosing all the factors means selecting the given number itself, and choosing none of the factors means selecting the trivial divisor 1.

Question 3:

Find the number of ways of factoring 441000 into 2 factors, m and n, such that m>1, n>1, and the GCD of m and n is 1.

Solution 3:

Consider the set A = {2^{3}, 3^{2}, 5^{3}, 7^{2}} associated with the prime factorization of 441000. It is clear that each element of A must appear in the prime factorization of m or in the prime factorization of n, but not in both. Moreover, the 2 prime factorizations must be composed exclusively of elements of A. It follows that the number of relatively prime pairs m, n is equal to the number of ways of partitioning A into 2 unordered nonempty, subsets (unordered as mn and nm mean the same factorization; recall the fundamental theorem of arithmetic).

The possible unordered partitions are the following:

A = \{ 2^{3}\} + \{ 3^{2}, 5^{3}, 7^{2}\} = \{3^{2}\}+\{ 2^{3}, 5^{3}, 7^{2}\} = \{ 5^{3}\} + \{ 2^{3}, 3^{2}, 7^{2}\} = \{ 7^{2}\}+\{ 2^{3}, 3^{2}, 5^{3}\},

and A = \{ 2^{3}, 3^{2}\} + \{ 5^{3}, 7^{2}\}=\{ 2^{3}, 5^{3}\} + \{3^{2}, 7^{2} \} = \{ 2^{3}, 7^{2}\} + \{ 3^{2}, 5^{3}\}

Hence, the required answer is 4+3=2^{4-1}+1=7.

Question 4:

Generalize the above problem by showing that any integer has 2^{k-1}-1 factorizations into relatively prime pairs m, n (m>1, n>1).

Solution 4:

Proof by mathematical induction on k:

For k=1, the result holds trivially.

For k=2, we must prove that a set of k distinct elements, Z = \{ a_{1}, a_{2}, a_{3}, \ldots, a_{k-1}, a_{k}\} has 2^{k-1}-1 sets. Now, one partition of Z is

Z = \{ a_{k}\} \bigcup \{ a_{1}, a_{2}, a_{3}, \ldots, a_{k-1}\} \equiv \{ a_{k}\} \bigcup W

All the remaining partitions may be obtained by first partitioning W into two parts — which, by the induction hypothesis, can be done in 2^{k-2}-1 ways — and then, including a_{k} in one part or other — which can be done in 2 ways. By the product rule, the number of partitions of Z is therefore

1 + (2^{k-2})(2)=2^{k-1}-1. QED.

Remarks: Question 1 can be done by simply enumerating or breaking it into cases. But, the last generalized problem is a bit difficult without the refined concepts of set theory, as illustrated; and of course, the judicious use of mathematical induction is required in the generalized case. 


Nalin Pithwa.