M3P14
M3P14
1
π =3+
1
7+
1
15 +
1
1+
1
292 +
1
1+
1
1+
1
1+
..
.
4 4 12
=0+ =0+ =3+
12 12 32
1+ 1+ 6+
32 22 52
2+ 2
3+ 2
6+
5 3 72
2+ 5+ 6+
.. .. ..
. . .
2 2 4
=2+ =2+ =2+
1
1 1·2 1·3
1 + 1+ 3+
1
1 2·3 3·5
2 + 1+ 4+
1
1 3·4 5·7
3 + 1+ 4+
.. .. ..
. . .
13
=3+
13 + 23
6+
13 + 2 3 + 3 3 + 4 3
6+
1 + 23 + 33 + 43 + 53 + 63
3
6+
13 + 2 3 + 3 3 + 4 3 + 5 3 + 6 3 + 7 3 + 8 3
6+
..
.
Syllabus
Prime numbers and factorisation. Euclid’s algorithm and consequences. Congruences. The structure of
(Z/nZ)× . Primality testing and factorisation. RSA algorithm. Quadratic reciprocity. Sums of squares.
Pell’s equation. Continued fractions. Diophantine approximation. Primes in arithmetic progressions.
Arithmetic functions. The distribution of prime numbers.
1
M3P14 Number Theory Contents
Contents
0 Introduction 4
5 Public-key cryptography 16
5.1 Messages as sequences of classes modulo n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2 The Rivest-Shamir-Adleman (RSA) algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3 Signing with RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4 Discrete logarithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6 Quadratic reciprocity 17
6.1 Quadratic residues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.2 Computing Legendre symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.3 Proof of quadratic reciprocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.4 Jacobi symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7 Sums of squares 22
7.1 Sums of two squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
7.2 Sums of four squares - the ring of quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.3 Proof of Lagrange’s theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
7.4 Sums of three squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
8 Pell’s equation 26
8.1 Pell’s equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.2 Quadratic subrings of C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.3 Factorisation in quadratic rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.4 Back to Pell’s equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.5 Constructing the fundamental 1-unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.6 The equation x2 − dy 2 = −1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
9 Continued fractions 30
9.1 Rational continued fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
9.2 Infinite continued fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
9.3 Best approximations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
9.4 Returning to Pell’s equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
9.5 Periodic continued fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2
M3P14 Number Theory Contents
10 Diophantine approximation 36
10.1 Liouville’s theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
10.2 Constructing transcendentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
10.3 Roth’s theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
12 Arithmetic functions 40
12.1 Dirichlet convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
12.2 Möbius inversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3
M3P14 Number Theory 0 Introduction
0 Introduction
Lecture 1
Roughly speaking number theory is the study of the integers. More specifically, problems in number theory Friday
often have a lot to do with primes and divisibility, congruences, and include problems about the rational 05/10/18
numbers. For example, solving equations in integers or in the rationals, such as x2 − 2y 2 = 1, etc. We
will be looking at problems that can be tackled by elementary means, but this does not mean easy. Also
the statements of problems can be elementary without the solution being elementary, such as Fermat’s last
theorem, or even known, such as the twin prime conjecture. Sometimes we will state interesting things, like
the prime number theorem, without proving them. Typically these will be things that we could prove if the
course was much longer. We will start the course with a look at prime numbers and factorisation, a review of
×
Euclid’s algorithm and consequences, congruences, the structure of (Z/nZ) , RSA algorithm, and quadratic
reciprocity. We will return to primes at the end, too. The following are typical questions here.
How do you tell if a number is prime?
How many primes are there congruent to a mod b for given a and b?
A warning is that we will be using plenty of things from the compulsory first and second year algebra courses,
about groups, rings, ideals, fields, Lagrange’s theorem, the first isomorphism theorem, and so on. You may
want to revise this material if you are not comfortable with it. The course is not based on any particular
book, although some material, such as continued fractions, was drawn from the following.
A Baker, A concise introduction to the theory of numbers, 1984
4
M3P14 Number Theory 1 Euclid’s algorithm and unique factorisation
3 = 12 − 9
= 12 − (21 − 12)
(120, 87) = (87, 33) 120 = 87 + 33
= 2 (12) − 21
= (33, 21) 87 = 2 (33) + 21
= 2 (33 − 21) − 21
= (21, 12) 33 = 21 + 12
= 2 (33) − 3 (21)
= (12, 9) 21 = 12 + 9
= 2 (33) − 3 (87 − 2 (33))
= (9, 3) 12 = 9 + 3
= 8 (33) − 3 (87)
= (3, 0) 9 = 3 (3) + 10.
= 8 (120 − 87) − 3 (87)
= 8 (120) − 11 (87) .
Theorem 6. If a, b ∈ Z, not both zero, then there exist r, s ∈ Z such that (a, b) = ra + sb.
Proof. Idea is to write (an , bn ) for the sequence of pairs in Euclid’s algorithm, and use downwards induction
on n. 1
1 Exercise
5
M3P14 Number Theory 1 Euclid’s algorithm and unique factorisation
a b a b a b
X+ Y = x+ y ⇐⇒ y − Y, X − x.
(a, b) (a, b) (a, b) (a, b) (a, b) (a, b)
2 Exercise
6
M3P14 Number Theory 2 Congruences and modular arithmetic
a + c ≡ b + d mod n, ac ≡ bd mod n.
Z/nZ = {0, . . . , n − 1} .
7
M3P14 Number Theory 2 Congruences and modular arithmetic
Example.
2x ≡ 3 mod 6 has no solutions as (2, 6) = 2 - 3.
2x ≡ 4 mod 6 if and only if x ≡ 2 mod 3, which has solutions x ≡ 2 mod 6 and x ≡ 5 mod 6.
The first part says that given any ai ∈ Z, there is a unique x mod m1 . . . mn with x ≡ ai mod mi . Write
M
M = m1 . . . mn , Mi = .
mi
Choose qi such that qi Mi ≡ 1 mod mi , using (Mi , mi ) = 1 because (mj , mi ) = 1 for all j 6= i. Then take
x = a1 q1 M1 + · · · + an qn Mn .
Then
x ≡ ai qi Mi ≡ ai mod mi .
8
×
M3P14 Number Theory 3 The structure of (Z/nZ)
9
×
M3P14 Number Theory 3 The structure of (Z/nZ)
In particular, if (g, n) = 1, then g Φ(n) = 1, by Euler’s theorem, so Proposition 19 implies that ordn g | Φ (n).
×
We want to prove that if p is prime, then (Z/pZ) is cyclic. Equivalently, we need to show that there exists
g such that ordp g = Φ (p) = p − 1. We will do this by counting the number of elements of each order. The
×
key point is that Z/pZ is a field. For any d ≥ 1, the elements of (Z/pZ) of order dividing d are exactly the
roots of the X d − 1 in Z/pZ, by Proposition 19.
Example. The equation X 2 = 1 has exactly two solutions modulo p for any prime p, namely ±1, but it
can have more modulo n if n is composite. For example, if n = 15, then 4 and 11 are also solutions, since
X 2 − 1 ≡ 0 mod n if and only if n | (X + 1) (X − 1), for example 15 | (4 + 1) (4 − 1).
×
Definition 20. g ∈ Z with (g, p) = 1 is a primitive root if ordp g = p − 1, that is (Z/pZ) = hgi.
Lemma 21. Let R be a commutative ring, and let P (X) ∈ R [X]. If α ∈ R has P (α) = 0, then there exists
Q (X) ∈ R [X] such that P (X) = (X − α) Q (X).
Example. If R = Z/15Z, X 2 − 1 = (X + 1) (X − 1) = (X + 4) (X − 4).
Proof. Induction on deg P , where deg P = 0 is obvious. Let deg P = d, and assume the result holds for
degree at most d−1. Let P (X) = cX d +. . . and S (X) = P (X)−cX d−1 (X − α). Then S (X) has degree at
most d−1. Also S (α) = 0. By induction, we can write S (X) = (X − α) R (X). Set Q (X) = cX d−1 +R (X).
Then (X − α) Q (X) = cX d−1 (X − α) + S (X) = P (X).
Theorem 22. Let F be a field. Let P (X) be a polynomial in F [X]. Then P (X) has at most d distinct
roots in F .
Proof. Induction on d = deg P , where d = 1 is obvious. If P has no roots, then we are done. Otherwise,
let α be a root. By Lemma 21, P (X) = (X − α) Q (X), and Q (X) has degree d − 1, so we are done by
induction.
×
Corollary 23. Let d be any divisor of p − 1. Then there are exactly d elements of (Z/pZ) of order dividing
d.
Proof. We have to show that X d − 1 has exactly d roots in Z/pZ. By Fermat’s little theorem, X p−1 − 1 has
exactly p − 1 roots. Since d | p − 1, we can write
p−1 −1
X p−1 − 1 = X d − 1 Xd d + · · · + 1 = X d − 1 Q (X) ,
deg Q = p − 1 − d.
Then X p−1 − 1 has exactly p − 1 roots, X d − 1 has at most d roots, and Q (X) has at most p − 1 − d roots,
by Theorem 22. So X d − 1 has exactly d roots.
Example. Let p = 7. There are
one element of order one,
three elements of order dividing three, so two elements of order three, and
Proof. For each d | n, the elements of {1, . . . , n} with (i, n) = n/d are exactly those of the form i = (n/d) j
for 1 ≤ j ≤ d and (j, d) = 1. There are exactly Φ (d) such elements. Since the n/d run over all the divisors
of n, we are done.
10
×
M3P14 Number Theory 3 The structure of (Z/nZ)
×
Theorem 25. Let p be prime, and let d | p − 1. Then there are exactly Φ (d) elements of (Z/pZ) of order
×
d. In particular, there are Φ (p − 1) primitive roots, and (Z/pZ) is cyclic.
Proof. Induction on d, where d = 1 is obvious. Assume the result holds for all d0 | d and d0 6= d. Then by
Lemma 24, X
Φ (d) = d − Φ (d0 ) .
d0 |d, d0 6=d
Now use the inductive hypothesis and Corollary 23.
Lecture 5
n × Tuesday
Proposition 26. Let p be an odd prime and n ≥ 1. Then (Z/p Z) is cyclic.
16/10/18
Proof. Consider three cases.
n = 1. Theorem 25.
n = 2. Let g be a primitive root modulo p. Claim that either g p−1 6≡ 1 mod p2 and g is a generator for
× × ×
Z/p2 Z , or g p−1 ≡ 1 mod p2 and g + p is a generator for Z/p2 Z . Either way, Z/p2 Z is
cyclic. Suppose firstly that
g p−1 6≡ 1 mod p2 .
×
= Φ p2 = p (p − 1). So ordp2 g | p (p − 1). On the other hand, g ordp2 g ≡ 1
Then # Z/p2 Z
2 ordp2 g
mod p , so g ≡ 1 mod p, so p − 1 | ordp2 g, because ordp g = p − 1 by assumption. But
ordp2 g 6= p − 1, as g p−1 6≡ 1 mod p2 . So ordp2 g = p (p − 1), as required. Suppose now that
g p−1 ≡ 1 mod p2 .
p−1
It suffices to show that (g + p) 6≡ 1 mod p2 , as we can then apply the analysis above with g + p
in place of g. By the binomial theorem,
p−1
(g + p) ≡ g p−1 + (p − 1) g p−2 p ≡ 1 + (p − 1) g p−2 p mod p2 .
p−1
Since p - (p − 1) g p−2 , (g + p) 6≡ 1 mod p2 , as required.
n ≥ 2. It suffices to show that if ordp2 g = p (p − 1), then ordpn g = pn−1 (p − 1). We do this by induction
on n. So assume that ordpn g = pn−1 (p − 1). Then ordpn g | ordpn+1 g, and ordpn+1 g | Φ pn+1 =
pn (p − 1). So either ordpn+1 g = pn (p − 1), or ordpn+1 g = pn−1 (p − 1). So we need to show that
n−1
gp (p−1)
6≡ 1 mod pn+1 .
n−2
To do this, consider g p (p−1) modulo pn−1 and modulo pn . Since Φ pn−1 = pn−2 (p − 1),
n−2 n−2
by Euler’s theorem, g p (p−1) ≡ 1 mod pn−1 . Write g p (p−1) = 1 + pn−1 t. Since ordpn g =
n−2
pn−1 (p − 1) by assumption, g p (p−1) 6≡ 1 mod pn , that is p - t. Then
p
pn−1 (p−1)
n−2
p (p−1) n−1 p n p 2(n−1) 2
t + · · · + pp(n−1) tp
g = g = 1+p t =1+p t+ p
2
≡ 1 + pn t mod pn+1 ,
since r (n − 1) ≥ n + 1 if and only if (r − 1) n ≥ r + 1 and p > 2, so
n+1 2n−1 2(n−1)+1 p 2(n−1)
p p =p p .
2
n−1
So g p (p−1)
6≡ 1 mod pn+1 , because p - t.
Example.
×
(Z/2Z) = {1}.
×
(Z/4Z) = {1, 3} is cyclic of order two, with 3 as a generator.
×
(Z/8Z) = {1, 3, 5, 7} is not cyclic, since 12 ≡ 32 ≡ 52 ≡ 72 ≡ 1 mod 8, so every element has order
two.
11
×
M3P14 Number Theory 3 The structure of (Z/nZ)
g 15 6= 1, g 10 6= 1, g 6 6= 1.
How about 3? 32 = 9, 34 = 19, 36 = 16, 38 = 20, 310 = 25, 315 = 30. So 3 is a primitive root modulo 31.
12
M3P14 Number Theory 4 Primality testing and factorisation
4.1 Factorisation
How do we factor three digit numbers, or small four digit numbers, say at most 400 if we wanted√ to factor
with a paper or a calculator? If n ≤ 400 and n√is composite, √
then it has a prime factor at most 400 = 20,
since if d | n then d (n/d) = n, so either d ≤ n or n/d ≤ n. So you only have to be able to check for
divisibility by
2, 3, 5, 7, 11, 13, 17, 19.
2, 5. Checking for divisibility is easy, by just looking at the last digit.
3, 11. Use that 10 ≡ 1 mod 3 and 10 ≡ −1 mod 3. So
X X X X i
ai 10i ≡ ai mod 3, ai 10i ≡ ai (−1) mod 11.
i i i i
So you can check divisibility by 3, or 9, by checking for the sum of the digits, and 11 by taking
the alternating sum.
7. 10x + y ≡ 0 mod 7 if and only if −2 (10x + y) ≡ 0 mod 7, if and only if x − 2y ≡ 0 mod 7.
13, 17, 19. There are no good tests.
If n ≤ 400 and n is not divisible by 2, 3, 5, 7, 11, then the smallest prime factor of n is at least 13. Since
133 > 400, it can have at most two prime factors. So if you want to factor numbers at most 400, you only
have to remember a short list
132 , 13 (17) , 13 (19) , 13 (23) , 13 (29) , 172 , 17 (19) , 17 (23) , 192 .
Example.
143 ≡ 1 − 4 + 3 ≡ 0 mod 11.
144 ≡ 1 + 4 + 4 ≡ 0 mod 9.
154 ≡ 15 − 2 (4) = 7 ≡ 0 mod 7.
Lecture 7
Factor four digit numbers by an algorithm due to Fermat. The idea is to first check for small prime factors Friday
by hand, say p = 2, . √
. . , 19. If n is composite and does not have any small factors, then the prime factors of 19/10/18
n should be close to n. If n = ab for a and b odd and a ≤ b, then
2 2 2 2
a+b b−a a+b b−a
n = ab = − , −n= .
2 2 2 2
2
If you know (a + b) /2 and (b − a) /2, you can recover a and b. So take m such that m2 ≤ n < (m + 1) . If
2
n = m2 , done. Otherwise check if (m + i) − n is a square for increasing i.
Example. Let n = 6077. Then 772 < 6077 < 782 , so
782 − 6077 = 7,
792 − 6077 = 164,
802 − 6077 = 323,
812 − 6077 = 484 = 222 .
Thus 6077 = 812 − 222 = (103) (59).
13
M3P14 Number Theory 4 Primality testing and factorisation
There exist algorithms for factoring n which run in better than exponential time in log n, such as the
quadratic sieve and the general number field sieve.
Example. Let n = 1649. Then 402 < 1649 < 412 , so
412 − 1649 = 32 = 25 ,
422 − 1649 = 115,
3 2
432 − 1649 = 200 = (2) (5) .
3 2
Since 412 ≡ 25 mod 1649 and 432 ≡ (2) (5) mod 1649,
2 2
802 ≡ (41) (43) = 17632 ≡ 1142 mod 1649.
Then
2
0 ≡ 1142 − 802 = (194) (34) = (2) (17) (97) mod 1649.
In fact, 1649 = (17) (97). Better for this last step would be to have computed
(194, 1649) = 97, (34, 1649) = 17.
Can do this quickly using Euclid’s algorithm. To make this into an efficient algorithm, need to have a way
given x1 , . . . , xr to find a subset whose product is a square. If we know the prime factorisation for the xi ,
we can write
xi = pa1 i1 . . . pakik .
Qr
Want to choose i = 0, 1 such that i=1 xi i is a square. Equivalently, for each j, want the exponent of pj to
be even, that is
Xr
i aij ≡ 0 mod 2.
i=1
Let
3 2
x1 = 25 , x2 = (5) (23) , x3 = (2) (5) , p1 = 2, p2 = 5, p3 = 23.
Ignore all numbers with a large prime factor, so here ignore 23. Then
5 0 1 0
1 2 ≡ 0 0 mod 2 ⇐⇒ 1 2 = 0 0
3 2 1 0
in Z/2Z, a field F2 , that is 1 + 2 = 0, so 1 = 2 = 1.
This step, solving linear equations in Z/2Z, can be done efficiently. The remaining difficulty is to find a
supply of m ∈ Z such that m2 −n has only small prime factors. The idea is that if we fix a list of small primes
to start with, we get congruence conditions on m. It turns out that there is a straightforward algorithm for
solving m2 ≡ n mod p. This gives two possible values for m mod p. If you do this for lots of primes p, you
get a supply of congruence conditions for m, so you can eliminate ever considering m such that m2 − n has
large prime factors.
Example. m2 = 1649 ≡ 2 mod 3 has no solutions.
14
M3P14 Number Theory 4 Primality testing and factorisation
Proof.
2
If n is prime, then an−1 ≡ 1 mod n by Fermat’s little theorem, so a(n−1)/2 ≡ 1 mod n, so
a(n−1)/2 ≡ ±1 mod n.
Suppose firstly that n = pk with p prime, and k ≥ 2. Try
a = 1 + p.
Then
n−1 n−1
a 2 ≡1+ p mod p2 ,
2
by the binomial theorem. If a(n−1)/2 ≡ ±1 mod n, then
n−1 n−1
±1 ≡ a 2 ≡ 1 + p ≡ 1 mod p,
2
so
n−1
1≡1+ p mod p2 ,
2
then p | (n − 1) /2, so p | n − 1. But p | n, a contradiction.
The remaining case is that n is composite but not a power of a prime. Write n = rs for r, s > 1, and
odd, and (r, s) = 1. By the Chinese remainder theorem,
Z/nZ ∼
= Z/rZ × Z/sZ.
Choose a such that
a ≡ −1 mod r, a≡1 mod s.
Then (a, r) = (a, s) = 1, so (a, n) = 1. Since n ≡ 3 mod 4, (n − 1) /2 is odd, so
n−1 n−1
a 2 ≡ −1 mod r, a 2 ≡1 mod s.
(n−1)/2
So a 6≡ ±1 mod n.
×
Lemma 31. Suppose that n ≡ 3 mod 4 is composite. Then the set of a ∈ (Z/nZ) which satisfy a(n−1)/2 ≡
×
±1 mod n is a proper subgroup of (Z/nZ) .
Proof. Certainly 1(n−1)/2 ≡ 1 mod n. If a(n−1)/2 ≡ ±1 mod n and b(n−1)/2 ≡ ±1 mod n,
−1
n−1
n−1 n−1 n−1 n−1
−1 2 −1
(ab) 2 ≡a 2 b 2 ≡ (±1) (±1) ≡ ±1 mod n, a ≡ a 2 ≡ (±1) ≡ ±1 mod n.
×
So this set is a subgroup of (Z/nZ) . It is a proper subgroup by Lemma 30.
×
Corollary 32. At most half the elements of (Z/nZ) satisfy a(n−1)/2 ≡ ±1 mod n.
×
Proof. The set of such elements is a proper subgroup of (Z/nZ) by Lemma 31, so it has index at least
two.
In fact, with a bit more work, you can improve this to show that at least 34 of the numbers 1 ≤ a ≤ n − 1
satisfy a(n−1)/2 6≡ ±1 mod n. So if you randomly choose numbers 1 ≤ a ≤ n − 1 x times, x and n is
composite, the probability that you find some a with a(n−1)/2 6≡ ±1 mod n is at least 1 − 14 . This gives
a probabilistic algorithm to check if n is prime in polynomial time. If you assume the generalised Riemann
hypothesis (GRH) you can find some
l
2
m n−1
1 ≤ a ≤ 2 (log n) , a 2 6≡ ±1 mod n.
15
M3P14 Number Theory 5 Public-key cryptography
5 Public-key cryptography
Public-key cryptography is private communication and identity verification.
16
M3P14 Number Theory 6 Quadratic reciprocity
6 Quadratic reciprocity
6.1 Quadratic residues
Let p be a prime number.
Definition 33. If (a, p) = 1, then a is a quadratic residue (QR) if and only if there is a solution to
x2 ≡ a mod p. If (a, p) = 1 and is not a QR, it is called a quadratic non-residue (QNR).
Example.
If p = 2, 1 is a QR.
2
If p = 3, 1 is a QR, and −1 is a QNR, since 12 ≡ (−1) ≡ 1 mod 3.
If p = 5, 1 and 4 are QRs, and 2 and 3 are QNRs, since 12 ≡ 42 ≡ 1 mod 5 and 22 ≡ 32 ≡ 4 mod 5.
Lemma 34. If p > 2 then there are exactly (p − 1) /2 QRs, and (p − 1) /2 QNRs modulo p.
Proof. The map
× ×
(Z/pZ) −→ (Z/pZ)
x 7−→ x2
is a group homomorphism with kernel {±1}. So the image has order (p − 1) /2, and the image is exactly the
QRs.
Proposition 35. Suppose that (a, p) = (b, p) = 1. Then
if a and b are both QRs, then ab is a QR,
if one of a and b is a QR and one is a QNR, then ab is a QNR, and
if a and b are both QNRs, then ab is a QR.
Proof. Let H be the image of
× ×
(Z/pZ) −→ (Z/pZ)
,
x 7−→ x2
×
that is H is the QRs. Then (Z/pZ) /H is a group of order two by Lemma 34, so it is cyclic of order two.
×
This statement is a restatement of Proposition 35, since (Z/pZ) = H ∪ 1 + H.
Definition 36. Let a ∈ Z and p a prime. Then the Legendre symbol is
1 a is a QR modulo p
a
p = 0 p|a .
−1 a is a QNR modulo p
17
M3P14 Number Theory 6 Quadratic reciprocity
2
Proof. Let g be a primitive root modulo p, and write a ≡ g r mod p for 0 ≤ r < p − 1. Now g (p−1)/2 =
p−1
g p−1 ≡ 1 mod p. So g (p−1)/2 ≡ ±1 mod p. Since g is a primitive root, 6≡ 1 mod p, so g (p−1)/2 ≡ −1
g 2
mod p. So
p−1 r
p−1
p−1
r
a 2 ≡ (g r ) 2 ≡ g 2 ≡ (−1) mod p.
But
2
a
p =1 ⇐⇒ ∃s ∈ Z, (g s ) ≡ a mod p
⇐⇒ 2s ≡ r mod p − 1
⇐⇒ r ∈ 2Z
r
⇐⇒ (−1) ≡ 1 mod p.
so in fact p−1
−1
p = (−1) 2 .
Then (
p−1 1 p ≡ 1 mod 4
(−1) 2 = .
−1 p ≡ 3 mod 4
3 Exercise
18
M3P14 Number Theory 6 Quadratic reciprocity
Example. If p ≡ 1 mod 8, say p = 1+8n, then q = 4n. Odd integers in 1, . . . , 4n are 1, 3, . . . , 4n−3, 4n−1,
so r = 2n.
Example.
27 = 1, since 2 ≡ 32 mod 7.
112
= −1, since squares modulo 11 are 1, 4, 9, 5, 3.
2
−1 −2
2
−1 2
11 = −1, so 11 = 11 11 = (−1) = 1, since −2 ≡ 3 mod 11.
Example.
p5 = p
5 for p 6= 5. QRs modulo 5 are 1 and 4. So
(
5 1 p ≡ ±1 mod 5
p = .
−1 p ≡ ±2 mod 5
What is 3
p for p 6= 3? If p ≡ 1 mod 4, then
(
3 p
1 p ≡ 1 mod 3
p = 3 = .
−1 p ≡ −1 mod 3
If p ≡ −1 mod 4, then (
3 p
1 p ≡ −1 mod 3
p =− 3 = .
−1 p ≡ 1 mod 3
So (
p ≡ ±1 mod 12
3 1
p = .
−1
p ≡ ±5 mod 12
196 2
3 2
3
= 19 19 = (−1) (−1) = 1, since 19 = −1, because 19 ≡ 3 mod 8, and 19 ≡ −1 mod 12,
by the above.
In general to compute ap , we could do the following. Use that if a ≡ b mod p then ap = pb . So
without loss of generality |a| < p. Then write a = ± i qisi for qi prime. Then
Q
Y si
a ±1 qi
p = p p .
i
si si
qi qi qi
If si is even, then p = 1. If si is odd, then . We have formulas for −1
p p= and 2
p . If q
p
is an odd prime, q < p, then use quadratic reciprocity to relate pq and pq . Then repeat modulo q.
19
M3P14 Number Theory 6 Quadratic reciprocity
For the third set of representatives, select the pairs (x, y) which correspond via the Chinese remainder
theorem to the set
1 ≤ i ≤ pq−1
2 (i, pq) = 1 .
Let C be the product of these coset representatives. What is the x-coordinate of C? It is
pq−1
Y2
i.
i=1, (i,pq)=1
So
pq−1 pq−1 pq−1
,
Y2 Y2 Y2
i= i i , (1)
i=1, (i,pq)=1 i=1, (i,p)=1 i=1, (i,p)=1, q|i
pq−1 q−1 q−1 p−1
p 2 p 2 + 2
Y2 Y Y
i= i i , (2)
i=1, (i,p)=1 i=1, (i,p)=1 q−1
i=p 2 +1, (i,p)=1
pq−1 p−1
Y2 Y2 p−1
p−1
i= qj = q 2
2 !. (3)
i=1, (i,p)=1, q|i j=1, (j,p)=1
Combining (1) , (2) , (3), get that the x-coordinate of the product is
pq−1 q−1 q−1
2 p−1
Y (p − 1)! 2
2 ! (−1) 2
i= p−1 = p−1 .
p−1
i=1, (i,pq)=1 q 2
2 ! q 2
20
M3P14 Number Theory 6 Quadratic reciprocity
a
Y a ri
b = pi .
i
a a
A warning is that = 1 does not imply that a is a square modulo b. On the other hand,
b b = −1 implies
that a is not a square modulo b. Lecture 13
Lemma 43. Friday
02/11/18
1. a1ba2 = ab1 ab2 and b1ab2 = ba1 a
b2 .
−1
(b−1)/2
4. b = (−1) .
2
= (−1)(
2
b −1)/8
5. b .
6. If a, b > 0 are both odd
a−1 b−1
a b 2 2
b a = (−1) .
Proof. All of these statements are true for Legendre symbols, that is for b prime, and a prime in 6. 1 to 3
follow immediately, and 4 to 6 also follows from 1 and the corresponding statements for Legendre symbols.
For 5, it is enough to show that if it holds for b1 and b2 , then it holds for b1 b2 . Since
2 2 2
b1 b2 = b1 b2 ,
21
M3P14 Number Theory 7 Sums of squares
7 Sums of squares
Which integers are the sum of two squares? Which integers are the sum of four squares?
Theorem 47 (Fermat’s two square theorem). If p ≡ 1 mod 4 is prime, then p is a sum of two squares.
Lemma 46 and Theorem 47 together allow you to give a complete classification of the integers which are
sums of two squares, in terms of their prime factorisations.
Definition 48. A ring R is a Euclidean domain if it is an integral domain, that is ab = 0 implies that
a = 0 or b = 0, and there exists a function N : R → Z≥0 such that for all a, b ∈ R with b 6= 0, there exist
q, r ∈ R such that a = qb + r, and r = 0 or N (r) < N (b).
If R is a Euclidean domain, then you can carry out Euclid’s algorithm. In particular, irreducible elements
are the same as prime elements, and every element can be factored as a product of primes, uniquely up to
reordering and multiplication by units. Then Z [i] together with N is a Euclidean domain. By definition,
n ∈ Z is a sum of two squares if and only if there exists z ∈ Z [i] with N (z) = n. Since N (zw) = N (z) N (w),
all we have to do is to figure out what the primes in Z [i] are, and what their norms are. The units in Z [i]
are ±1 and ±i. 4 Two elements of Z [i] are associates if their ratio is a unit, that is z and w are associates
if z = uw for u = ±1, ±i. Lecture 14
2 Tuesday
Lemma 49. Let p be a prime in Z [i]. Then there is a prime q of Z such that either N (p) = q or N (p) = q .
06/11/18
In the latter case, p is an associate of q. Given q a prime in Z, there exists p such that N (p) = q if and only
if q is a sum of two squares.
Proof. Write n = N (p), and let n = q1s1 . . . qrsr be the prime factorisation of n in Z. By definition n = pp̄,
so p | n in Z [i], and so since p is prime, p | qi for some i. Write q = qi . Then p | q implies that q = pv for
some v, so N (p) N (v) = N (pv) = N (q) = q 2 . If N (p) = 1, then p is a unit, a contradiction. So N (p) | q 2 ,
so N (p) = q or N (p) = q 2 , as claimed. If N (p) = q 2 , then N (v) = 1, so v is a unit, and since q = pv, p is
an associate of q, by definition. If N (p) = q, then writing p = a + bi, we have q = a2 + b2 . Conversely, if
q = a2 + b2 = (a + bi) (a − bi), then since p | q, we have either p | a + bi or p | a − bi, so N (p) | N (a + bi) = q
or N (p) | N (a − bi) = q, and either way N (p) = q.
4 Exercise
22
M3P14 Number Theory 7 Sums of squares
Corollary 50. The primes in Z [i] are either of the form a + bi with a2 + b2 a prime in Z, or are primes of
Z which are not sums of two squares.
Theorem 51. If p = 2 or p ≡ 1 mod 4, then p is a sum of two squares.
Proof. By Corollary 50, we just have to show that p is not a prime in Z [i]. There exists n such that n2 ≡ −1
mod p. If p = 2 obvious, and if p ≡ 1 mod 4,
p−1
−1
p = (−1) 2 = 1,
Proof. Suppose n is of this form. Then 2, each pi , and each qi2 are all sums of two squares, so n is a sum of
two squares by Lemma 46. Conversely suppose that n = a2 + b2 , and write a + bi as a product of primes in
Z [i]. Then n = N (a + bi) is the product of the norms of these primes, and we already saw that the norms
of primes in Z [i] are either 2, a prime which is 1 mod 4, or the square of a prime which is 3 mod 4.
a + bi + cj + dk, a, b, c, d ∈ R,
such that
addition is
(a + bi + cj + dk) + (A + Bi + Cj + Dk) = (a + A) + (b + B) i + (c + C) j + (d + D) k,
multiplication is
ij = −ji = k, jk = −kj = i, ki = −ik = j.
∗
If z = a + bi + cj + dk, we write z ∗ = a − bi − cj − dk, so (zw) = w∗ z ∗ .
Define
N (z) = zz ∗ = a2 + b2 + c2 + d2 .
∗
Then N (zw) = zw (zw) = zww∗ z ∗ = zN (w) z ∗ = zz ∗ N (w) = N (z) N (w), because N (w) ∈ R. So
a2 + b2 + c2 + d2 x2 + y 2 + z 2 + w2 = N (a + bi + cj + dk) N (x + yi + zj + wk)
In particular, if m and n are sums of four squares, then mn is a sum of four squares. So to prove Lagrange’s
theorem, it suffices to show that all primes are sums of four squares.
23
M3P14 Number Theory 7 Sums of squares
x2 + y 2 + 1 = pr,
for some r. Since the congruence x2 + y 2 + 1 ≡ 0 mod p only depends on x and y modulo p, we can find x
and y with −p/2 < x, y < p/2. Then
x2 + y 2 + 1
= r < p.
p
Proposition 55. Suppose that
x2 + y 2 + z 2 + w2 = pr, 1 ≤ r < p.
Proposition 55 implies that p is a sum of four squares, starting with x, y, r as above, z = 1, and w = 0.
Proof.
Suppose firstly that r is even. Then either x, y, z, w are all even, all odd, or two are even and two are
odd. So without loss of generality x ≡ y mod 2 and z ≡ w mod 2. Then take
x+y x−y z+w z−w r
x0 = , y0 = , z0 = , w0 = , r0 = .
2 2 2 2 2
24
M3P14 Number Theory 7 Sums of squares
Suppose now that r is odd, and choose a, b, c, d ∈ (−r/2, r/2) such that
Then
a2 + b2 + c2 + d2 ≡ x2 + y 2 + z 2 + w2 = pr ≡ 0 mod r.
2
Write a2 + b2 + c2 + d2 = rr0 . Then rr0 < 4 (r/2) = r2 , so 0 ≤ r0 < r. If r0 = 0 then a = b = c = d = 0,
so r0 divides each of x, y, z, w. Since x2 + y 2 + z 2 + w2 = pr, we get r2 | pr so r | p, and since r < p,
we get r = 1, and we are done. Otherwise 1 ≤ r0 < r. Then
(rr0 ) (rp) = a2 + b2 + c2 + d2 x2 + y 2 + z 2 + w2
2 2
= (ax + by + cz + dw) + (−ay + bx + cw − dz)
2 2
+ (−az − bw + cx + dy) + (−aw + bz − cy + dx) .
Then
ax + by + cz + dw ≡ x2 + y 2 + z 2 + w2 ≡ 0 mod r,
−ay + bx + cw − dz ≡ −xy + yx + zw − wz ≡ 0 mod r,
−az − bw + cx + dy ≡ −xz − yw + zx + wy ≡ 0 mod r,
−aw + bz − cy + dx ≡ −xw + yz − zy + wx ≡ 0 mod r.
So take
ax + by + cz + dw −ay + bx + cw − dz
x0 = , y0 = ,
r r
−az − bw + cx + dy −aw + bz − cy + dx
z0 = , w0 = .
r r
Remark 56. This can be interpreted as a version of Euclid’s algorithm in the ring
a + bi + cj + dk
a ≡ b ≡ c ≡ d mod 2 .
2
Note. This ring is non-commutative, and also, for example, 5 = (1 − 2i) (1 − 2i) = (1 + 2j) (1 − 2j), so you
have to be careful with unique factorisation, etc.
4a (8k + 7) .
Proving that numbers are not of this form is beyond this course. Serre’s a course in arithmetic is a good
place to look.
25
M3P14 Number Theory 8 Pell’s equation
8 Pell’s equation
8.1 Pell’s equation
Let d ∈ Z>1 be squarefree. Pell’s equation is
x2 − dy 2 = 1.
Example. Let d = 2. Then (x, y) = (3, 2) is a solution. In fact, there are infinitely many solutions, and
this is true for any d.
We will find it useful to write √ √
x2 − dy 2 = x + dy x − dy .
This suggests that we should look at a ring like
h√ i n √ o
Z d = a + b d a, b ∈ Z .
h i h i
Also Z p1 contains 1/pn for all n, so in fact Z p1 = {a/pn | a ∈ Z, n ≥ 0}.
An alternative definition is that Z [α] is the intersection of all subrings of C containing α. Lecture 16
Lecture 16 is a problems class. Friday
09/11/18
8.2 Quadratic subrings of C
Lecture 17
Definition 59. Say that α ∈ C is an algebraic integer of degree two if it is a root of a polynomial Tuesday
13/11/18
X 2 + aX + b, a, b ∈ Z, α∈
/ Z.
Example.
α = i is a root of X 2 + 1.
√
α = d is a root of X 2 − d for d > 1 squarefree.
Proposition 60. If α is an algebraic integer of degree two, then
Z [α] = {x + yα | x, y ∈ Z} .
26
M3P14 Number Theory 8 Pell’s equation
If α is an algebraic integer of degree two, say that Z [α] is a real quadratic subring of C if α ∈ R, and an
imaginary quadratic subring of C if α ∈ / R. Let α∗ be the other root of X 2 + aX + b = 0.
√ ∗ √
Example. i∗ = −i = ī and d = − d.
If z = x + yα ∈ Z [α], write z ∗ = x + yα∗ . If Z [α] is imaginary quadratic, then α∗ = ᾱ, and z ∗ = z̄. This is
not true if Z [α] is real quadratic. Define N (z) = zz ∗ . Since α and α∗ are the roots of X 2 + aX + b, we have
α + α∗ = −a and αα∗ = b. If z = x + yα, then
N (z) = (x + yα) (x + yα∗ ) = x2 + xy (α + α∗ ) + y 2 αα∗ = x2 − axy + by 2 ∈ Z.
∗ ∗
We have (zw) = z ∗ w∗ , so N (z) N (w) = zz ∗ ww∗ = (zw) (zw) = N (zw). So N : Z [α] → Z is multiplicative.
Then N (x + yα) = 0 if and only if x = y = 0. If Z [α] is imaginary quadratic then z ∗ = z̄, and N (z) ≥ 0.
5
So solutions to Pell’s equation are the same thing as elements of Z [α] of norm one.
27
M3P14 Number Theory 8 Pell’s equation
√ √ h√ i×,1
Lemma 63. Let z = x + y d and z 0 = x0 + y 0 d be two elements of Z d with z, z 0 > 1, that is
x, y, x0 , y 0 > 0. Then z > z 0 if and only if y > y 0 .
√ √ √
Proof. z − 1/z = x + y d − x − y d = 2y d, so just need to check that z > z 0 if and only if z − 1/z >
z 0 − 1/z 0 . But z − 1/z is increasing, since its derivative is 1 + 1/z 2 > 0.
h√ i×,1 Lecture 18
Suppose that there exists z ∈ Z d , so z 6= ±1. By replacing z by ±z ±1 , we can assume that z > 1. So Wednesday
√ 14/11/18
by Lemma 62, if z = x + y d, then x, y > 0. Let
√ h√ i×,1
=x+y d∈Z d , x, y > 0,
h√ i
with y as small as possible. Call the fundamental 1-unit of Z d .
h√ i×,1
Proposition 64. Suppose that Z d 6= {±1}, and let be the fundamental 1-unit. Then every element
h√ i×,1
n
of Z d is of the form ±n for some n ∈ Z. Conversely, N (±n ) = N (±1) N () = 1.
h√ i×,1
Proof. Let z ∈ Z d , so z 6= ±1. After replacing z by ±z ±1 , we may assume that z > 1. Choose n ≥ 0
h√ i×,1
−n
such that n ≤ z < n+1 . Then 1 ≤ z−n < , and N (z−n ) = N (z) N () = 1. So z−n ∈ Z d . So
by the choice of , and Lemma 63, we have z−n = 1, that is z = n .
√
Example. Let d = 2 and x2 − 2y 2 = 1. Then y = 2 and x = 3 is a solution. So = 3 + 2 2. Then
√ 2 √ 2
2 = 3 + 2 2 = 17 + 12 2, and 172 − 2 (12) = 1.
28
M3P14 Number Theory 8 Pell’s equation
Corollary 66. For any α ∈ R \ Q, there exist infinitely many pairs p, q ∈ Z such that
p 1
α− < 2.
q q
Proof. Certainly there exists p for q = 1. It is then enough to prove that if |α − p/q| < 1/q 2 , there exist p0
and q 0 such that
p0 1 p0 p
α− 0 < 2 , α− 0 < α− .
q (q 0 ) q q
Choose Q such that 1/Q < |α − p/q|. By Theorem 65, there exist p and q 0 with
0
p0 1 1
1 ≤ q 0 < Q, α− < < 2.
q0 Qq 0 (q 0 )
Also
p0 1 1 p
α− < ≤ < α− ,
q0 Qq 0 Q q
as required.
We can now show the following.
Theorem 67. If d > 1 is squarefree, then there exist x and y such that y 6= 0 and x2 − dy 2 = 1.
√
Proof. By Corollary 66, there exist infinitely many (pi , qi ) for pi , qi > 0 such that pi /qi − d < 1/qi2 , that
√
is pi − qi d < 1/qi . Then
√ √ √ 1 √ √
pi + qi d ≤ pi − qi d + 2qi d < + 2qi d < 3qi d.
qi
So
√ √ √ √ √
1
N pi + qi d = pi + qi d pi − qi d < 3qi d = 3 d.
qi
√ √ √
So there exists M ∈ −3 d, 3 d such that N pi + qi d = M for infinitely many i. Then there exists
(p0 , q0 ) such that
pi ≡ p0 mod M, qi ≡ q0 mod M,
for infinitely many i. Now consider (pi , qi ) 6= (pj , qj ) of this form, that is
√ √
N pi + qi d = N pj + qj d = M, pi ≡ pj mod M, q i ≡ qj mod M.
Then √ √
√ √
pi − qi d pi − qi d pj + qj d (pi pj − dqi qj ) + (pi qj − pj qi ) d
√ = = ,
pj − qj d M M
pi qj ≡ pj qi mod M, pi pj − dqi qj ≡ p2i − dqi2 = M ≡ 0 mod M.
So √ !
pi − qi d M
N √ = = 1,
pj − qj d M
√ √ h√ i×,1
so pi − qi d / pj − qj d ∈ Z d , as required.
29
M3P14 Number Theory 9 Continued fractions
9 Continued fractions
9.1 Rational continued fractions
Let p/q ∈ Q. Write
p p
= a0 + r0 , a0 = ∈ Z, 0 ≤ r0 < 1.
q q
If ri 6= 0, write
1 1
= ai+1 + ri+1 , ai+1 = ∈ Z≥1 , 0 ≤ ri+1 < 1.
ri ri
Eventually get some rn = 0. Write
p 1
= a0 + .
q 1
a1 +
1
··· +
an
Example.
40 2 19 1 40 1
=2+ , =9+ =⇒ =2+ .
19 19 2 2 19 1
9+
2+0
α = a0 + r0 , a0 = bαc ∈ Z, 0 ≤ r0 < 1.
If a0 , . . . , an ∈ R, then
1
[a0 ; a1 , . . . , an ] = a0 + .
1
a1 +
1
··· +
an
30
M3P14 Number Theory 9 Continued fractions
Suppose now that ai ≥ 1 if i ≥ 1. Then qi = ai qi−1 + qi−2 ≥ qi−1 + qi−2 . So the qi form an increasing
sequence, in fact with qi ≥ qi−1 + qi−2 ≥ 2qi−2 , so it even increases exponentially. If a0 , a1 , · · · ∈ R is an
infinite sequence with ai ≥ 1 for all i, say that pi /qi is the i-th convergent to
1
a0 + .
1
a1 +
1
a2 +
...
Lemma 69. For all n,
n−1
pn qn−1 − qn pn−1 = (−1) .
Proof. Obvious for n = 1. For the inductive step,
pn qn−1 − qn pn−1 = (an pn−1 + pn−2 ) qn−1 − (an qn−1 + qn−2 ) pn−1
= pn−2 qn−1 − qn−2 pn−1
= − (pn−1 qn−2 − qn−1 pn−2 ) .
Note. If ai ∈ Z, then pi , qi ∈ Z, and Lemma 69 implies that (pn , qn ) = 1. In general, Lemma 69 implies
that
pn pn−1 1
− = .
qn qn−1 qn qn−1
Pn
If ai ≥ 1 for all i ≥ 1, then the sequence qi increases exponentially. So i=1 1/qi qi−1 converges, so that
(pn /qn ) is a Cauchy sequence, so it converges.
31
M3P14 Number Theory 9 Continued fractions
Lecture 20
Lemma 70. Let α ∈ R \ Q, and let [a0 ; a1 , a2 , . . . ] be the corresponding continued fraction. Then pn /qn < α
Tuesday
if n is even, and pn /qn > α if n is odd.
20/11/18
Proof. Induction on n.
n = 0. a0 = bαc < α and p0 /q0 = a0 /1 = a0 .
n odd. By induction, we have [a1 ; a2 , . . . , an ] < 1/ (α − a0 ), since α = a0 + 1/ (a1 + 1/ . . . ). That is,
α − a0 < 1/ [a1 ; a2 , . . . , an ], that is
1 pn
α < a0 + = [a0 ; a1 , . . . , an ] = .
[a1 ; a2 , . . . , an ] qn
n even. The same argument with >.
Corollary 71. Assume α ∈ R \ Q and a0 , a1 , · · · ∈ Z be coming from its continued fraction. Let pn /qn =
[a0 ; a1 , . . . , an ] be the n-th convergent. Then
pn 1
α− < .
qn qn qn+1
In particular, pn /qn → α as n → ∞.
Proof. Either pn /qn < α < pn+1 /qn+1 or pn /qn > α > pn+1 /qn+1 , by Lemma 70. Either way,
pn pn pn+1 1
−α < − ≤ ,
qn qn qn+1 qn qn+1
by Lemma 69.
Note. 1/qn qn+1 < 1/qn2 , so the sequence (pn /qn ) satisfies the requirements of Dirichlet’s theorem.
32
M3P14 Number Theory 9 Continued fractions
33
M3P14 Number Theory 9 Continued fractions
Example.
√
3 = [1; 1, 2, 1, 2, . . . ] = 1; 1, 2 .
√ √ √ √ √ √
2=1+
2 − 1 , 1/ 2 − 1 = 2 + 1 = 2 + 2 − 1 , so 2 = 1; 2 .
√ √ √ √ √ √
5=2+
5 − 2 , 1/ 5 − 2 = 5 + 2 = 4 + 5 − 2 , so 5 = 2; 4 .
√
7 = 2; 1, 1, 1, 4 .
√
13 = 3; 1, 1, 1, 1, 6 .
√
43 = 6; 1, 1, 3, 1, 5, 1, 3, 1, 1, 12 .
Definition 77. We say that [a0 ; a1 , a2 , . . . ] is eventually periodic if there exist N, d > 0 such that
an+d = an for all n ≥ N . We say that it is periodic if we can take N = 0.
Fact 78. The following are facts.
√
The continued fraction of d is eventually periodic.
In fact, it is of the form
a0 ; a1 , . . . , am−1 , 2a0 .
There is a solution to x2 − dy 2 = −1 if and only if m is odd, in which case the solutions are
34
M3P14 Number Theory 9 Continued fractions
Example.
Let x2 − 43y 2 = ±1, so m = 10 is even, so there are no solutions to x2 − 43y 2 = −1. The smallest
solution for x2 − 43y 2 = 1 is p9 and q9 . Then
i 0 1 2 3 4 5 6 7 8 9
a 6 1 1 3 1 5 1 3 1 1
,
p 6 7 13 46 59 341 400 1541 1941 3482
q 1 1 2 7 9 52 61 235 296 531
2
so p9 = 3482, so 34822 − 43 (531) = 1 is the smallest solution.
For 13, m = 5 so p4 and q4 is the smallest solution for x2 − 13y 2 = −1 and p9 and q9 is the smallest
solution for x2 − 13y 2 = 1. Then
i 0 1 4 2 3
a 3 1 1 1 1
,
p 3 4 18 7 11
q 1 1 5 2 3
2 2 √
so 18 − 13 (5) = −1 is the smallest solution, and N 18 + 5 13 = −1, so
√ 2 √
N 18 + 5 13 = N 649 + 180 13 = 1.
√
In fact, it follows from our facts that this is the fundamental 1-unit, that is p9 + q9 13.
In fact, the converse is also true. All quadratic irrationals have eventually periodic continued fractions.
35
M3P14 Number Theory 10 Diophantine approximation
10 Diophantine approximation
10.1 Liouville’s theorem
Definition 81. Let d ∈ Z≥1 . Then α ∈ C is algebraic of degree d if there exists a polynomial of degree
d with integer coefficients and α as a root, and there does not exist such a polynomial of smaller degree.
Example. d = 1 is Q and d = 2 is the quadratic irrationals.
Theorem 82 (Liouville’s theorem). Let α ∈ R be algebraic of degree d. Then for any e ∈ R>d , there are
only finitely many p/q ∈ Q with
p 1
− α < e.
q q
Proof. Let P (X) be a polynomial of degree d with coefficients in Z, with P (α) = 0. Choose > 0 such that
the only root of P (X) in [α − , α + ] is α. Write P (X) = (X − α) Q (X). Then Q (X) is a polynomial of
degree d − 1 with real coefficients, so in particular it is continuous, so there exists K such that |Q (x)| ≤ K
for x ∈ [α − , α + ]. Assume that |p/q − α| < 1/q e . We may assume that q is large enough that 1/q e < .
Since P has integer coefficients and is of degree d, we have |P (p/q)| ≥ 1/q d . Note that P (p/q) 6= 0, or we
could replace P by P 0 with P (X) = (qX − p) P 0 (X). Since |p/q − α| < , p/q ∈ [α − , α + ], so
1 p p p p K
≤ P = −α Q ≤ K −α < e.
qd q q q q q
So K > q e−d , so K 1/(e−d) > q. So there are only finitely many possible q, so only finitely many p/q.
∞
X 1 1 1 1 1 2
|α − αk | = = 1 + + . . . = 1 + + . . . < k+1 .
10n! 10(k+1)! 10(k+2)!−(k+1)! q k+1 10k+1 q
n=k+1
If d ∈ Z>0 , and k > d, then 2/q k+1 < 1/q d . So there exist infinitely many p/q = αk such that |α − p/q| <
1/q d . Take d arbitrarily large, so α is transcendental.
36
M3P14 Number Theory 11 Primes in arithmetic progressions
Then Q > 1, and Q ≡ 3 mod 4, so Q has a prime factor q which has q ≡ 3 mod 4. Then q ∈
/ S, so we are
done.
Lemma 87. Let x be even, and p be a prime factor of x2 + 1, then p ≡ 1 mod 4.
Proof. Certainly p is odd. Then x2 + 1 ≡ 0 mod p, so x2 ≡ −1 mod p, so −1
p = 1, so p ≡ 1 mod 4.
37
M3P14 Number Theory 11 Primes in arithmetic progressions
Theorem 91. Let p 6= q be prime, and let a ∈ Z. Then p | Φq (a) if and only if a has order q mod p.
Proof. a has order q mod p if and only if aq ≡ 1 mod p and a 6≡ 1 mod p. If p | Φq (a) then p | aq − 1. If
also a ≡ 1 mod p, then Φq (a) ≡ Φq (1) ≡ q 6≡ 0 mod p, a contradiction. Conversely if aq ≡ 1 mod p and
a 6≡ 1 mod p, then (aq − 1) / (a − 1) ≡ 0 mod p.
Lecture 24
Wednesday
Corollary 92. If p 6= q is prime, and a ∈ Z, and p | Φq (a), then p ≡ 1 mod q.
28/11/18
Proof. By Theorem 91, a has order q mod p. But ap−1 ≡ 1 mod p, by Fermat’s little theorem. So
q | p − 1.
Theorem 93. Let q be prime. Then there are infinitely many primes with p ≡ 1 mod q.
Proof. Let S be a finite set of primes which are congruent to 1 mod q. Let
Y
R= p.
p∈S
Consider Φq (qR) ≥ qR + 1 > 1. Let p be a prime factor of Φq (qR). By Corollary 92, either p = q, or p ≡ 1
q−1
mod q. Since Φq (qR) = (qR) + · · · + 1 ≡ 1 mod qR, so p 6= q, p ∈
/ S, and p ≡ 1 mod q.
Proof. Each side is a monic polynomial, so we just need to check that the roots are the same, with multipli-
cities. The left hand side are the n-th roots of unity, with multiplicity one each. The right hand side is Φd ,
the primitive d-th roots of unity, with multiplicity one. Each n-th root of unity is a primitive d-th root of
unity for some unique d | n. The result follows.
and assume that not all ai ∈ Z. Let q be maximal with aq ∈ / Z. Let e = deg P , so P (X) = X e + be−1 X e−1 +
q+e
· · · + b0 . Then the coefficient of X in Φn (X) P (X) is
38
M3P14 Number Theory 11 Primes in arithmetic progressions
Definition 97. Let F be any field, and let P (X) ∈ F [X]. Then P 0 (X), the derivative of P (X), is defined
Pd
as follows. If P (X) = n=0 an X n , then
d
X
P 0 (X) = nan X n−1 .
n=1
0 0
Note. (P + Q) = P 0 + Q0 and (P Q) = P 0 Q + P Q0 .
2
Lemma 98. Suppose that (X − α) divides P (X). Then α is a root of both P and P 0 .
2
Proof. Write P (X) = (X − α) R (X). Then
2
P 0 (X) = (X − α) R0 (X) + 2 (X − α) R (X) = (X − α) ((X − α) R0 (X) + 2R (X)) .
so a is a root of Φn (X) mod p, that is p | Φn (a). Conversely, suppose that p | Φn (a). Then a is a root of
Φn (X) mod p, so by (4), a is a root of X n − 1 mod p. We need to show that a is not a root of X d − 1 for
any d | n for d < n. Writing Y
Xd − 1 = Φe (X) ,
e|d
a would be a root of Φe (X) for some e | d | n. So by (4), a is a root of both Φn (X) and Φe (X), so a is a
repeated root of X n − 1 mod p. This contradicts Corollary 99.
Corollary 101. If p - n, and a ∈ Z, then if p | Φn (a), then p ≡ 1 mod n.
Proof. a has order n mod p by Theorem 100, so n | p − 1, by Fermat’s little theorem.
For each k, let Qk = Φn (knR) ∈ Z. Note that not all Qk are ±1, since Φn (X) is a non-constant polynomial.
n
Thus choose k large enough that Qk > 1, so there is a prime p dividing Qk . Since Qk divides (knR) − 1,
no prime dividing n or R can divide Qk . Thus p is not in S, and by Corollary 101 p is congruent to 1
mod n.
Lecture 25
Lecture 25 is a problems class. Friday
30/11/18
39
M3P14 Number Theory 12 Arithmetic functions
12 Arithmetic functions
Lecture 26
An arithmetic function is a function f : Z≥1 → C, such as Φ. Tuesday
04/12/18
12.1 Dirichlet convolution
The set of arithmetic functions is a ring in the following way. Addition is (f + g) (n) = f (n) + g (n).
Multiplication is Dirichlet convolution f ∗ g,
X n X
(f ∗ g) (n) = f (d) g = f (a) g (b) .
d
d|n, d≥1 a,b≥1, ab=n
Example. f (4) = f (4) (1) + f (2) (2) + f (1) (4). This forces (1) = 1 and (2) = (4) = 0.
So (
1 n=1
(n) = .
0 n>1
Proposition 104 (Möbius inversion). If f and g are arithmetic functions then g = f ∗ 1 if and only if
f = g ∗ µ.
Proof. (f ∗ 1) ∗ µ = f ∗ (1 ∗ µ) = f ∗ = f , by Lemma 103, and (g ∗ µ) ∗ 1 = g ∗ (µ ∗ 1) = g ∗ = g.
P
Example. Let id (n) = n. Then id = Φ ∗ 1. That is, n = d|n Φ (d). So Φ = id ∗µ. So
X n X µ (d)
Φ (n) = µ (d) =n .
d d
d|n d|n
40
M3P14 Number Theory 13 The distribution of prime numbers
Taking logarithms,
1 2n
π (2n) ≥ log C1 .
2 log 2n
This gives the lower bound if X = 2n ∈ Z is even, but since π (X + 1) − π (X) ≤ 1, it is easy to get
the lower bound for all X. We will prove (5) by considering the prime factors of
2n Y
= pvp (n) .
n
p≤2n
Claim that
√
1. if p > 2n then vp (n) ≤ 1,
2. for all p ≤ 2n, pvp (n) ≤ 2n, and
3. p≤2n pvp (n) ≥ 4n / (2n + 1).
Q
41
M3P14 Number Theory 13 The distribution of prime numbers
So Y 4n
p≥ √ .
2n
p≤2n (2n + 1) (2n)
For n sufficiently
√
large, and any 4 > C1 , the right hand side is at least C1n , that is if K > 1, K n ≥
2n
(2n + 1) (2n) for all n sufficiently large. 7
P∞
1. In the first example sheet question 11, the exact power of p dividing m! is i=1 m/pi . So
∞
2n (2n)! X 2n n
= =⇒ vp (n) = i
−2 i .
n n!n! i=1
p p
√
For any x ∈ R, b2xc − 2 bxc ≥ 0, and in fact b2xc − 2 bxc = 0 or b2xc − 2 bxc = 1. If p > 2n,
then p2 > 2n, so all terms in the sum vanish if i ≥ 2, so the sum is at most one.
2. Note that the terms in the sum are zero as soon as pi > 2n, that is
log 2n log 2n
i> =⇒ vp (n) ≤ =⇒ pvp (n) ≤ 2n.
log p log p
3.
2n
4n
2n
X 2n 2n Y 2n
4n = 22n = (1 + 1) = ≤ (2n + 1) =⇒ pvp (n) = ≥ .
i=0
i n n 2n + 1
p≤2n
Claim that there exists C2 > 1 such that for all X sufficiently large, we have
Y
p ≤ C2X . (6)
X
2 ≤p≤X
Taking logarithms,
X X log C2
π (X) ≤ π + . (7)
2 log X
2
Suppose that X is large enough that (6) holds for X, . . . , X/2m−1 . Substituting X, . . . , X/2m−1 into
(7), and summing,
m X
X X
2i
π (X) ≤ π + 2 log C 2 .
2m i=1
log 2Xi
7 Exercise
42
M3P14 Number Theory 13 The distribution of prime numbers
√ √
Now fix X and choose m to be largest possible with 2m ≤ X. Then X/2m ≥ X, so (6) is indeed √
, X/2m−1 provided that X is sufficiently large. Since m is maximal such that 2m ≤ X,
valid for X, . . . √
we have 2m ≥ X/2. So
√
X X
π ≤ ≤ 2 X.
2m 2m
So substituting into the above,
m m
√ X √ √
X
2i 2 log C2 X X X
π (X) ≤ 2 X + 2 log C2 X
≤2 X+ 1 ≤ 2 X + (4 log C2 ) .
i=1
log 2i 2 log X i=1
2i log X
√
This gives our upper bound, because X X/ log X. Now remains to prove (6). We saw above that
if n ∈ Z then
2n
Y 2n X 2n
p≤ ≤ 4n = .
n i=0
i
n<p≤2n
Lecture 28
Lecture 28 is a problems class. Friday
07/12/18
13.3 The Brun-Titchmarsh theorem and the Selberg sieve
Lecture 29
What can we say about the number of primes p with X < p ≤ X + Y ? That is, π (X + Y ) − π (X). Think Tuesday
of Y being fixed for a moment. The best possible lower bound is zero. 11/12/18
Example. n! + 2, . . . , n! + n is a sequence of consecutive composite numbers.
It was conjectured, in 1920s, by Hardy and Littlewood that π (X + Y ) ≤ π (X) + π (Y ), that is π (X + Y ) −
π (X) ≤ π (Y ). This is no longer believed.
Theorem 107.
(2 + o (1)) Y
π (X + Y ) − π (X) ≤ ,
log Y
where o (1) is as Y → ∞ and X is fixed.
In X + 1, . . . , X + Y , about half of these are divisible by two, about a third of these are divisible by three,
and about a sixth of these are divisible by six. If p1 , . . . , pk are primes, the error term is 2k , so can only
consider the first log Y primes, which implies Theorem 107 for Y / log log Y . Selberg’s idea is to weight the
inclusion-exclusion count.
Proof. Let λ1 , λ2 , · · · ∈ R be any sequence with λ1 = 1. Let R < Y be fixed for now. Later we will choose
1
R=Y 2 − . Set 2
X
ν (n) = λd ≥ 0.
d|n, d≤R
43
M3P14 Number Theory 13 The distribution of prime numbers
P
Now have to choose λi to minimise X≤n≤X+Y ν (n), so
2
X X X X X X
ν (n) = λd = λd1 λd2
X<n≤X+Y X<n≤X+Y d|n, d≤R X<n≤X+Y d1 |n, d1 ≤R d2 |n, d2 ≤R
X X X Y (d1 , d2 )
= λd1 λd2 1 = λd1 λd2 + O (1) ,
d1 d2
d1 ,d2 ≤R X<n≤X+Y, d1 |n, d2 |n d1 ,d2 ≤R
Now choose λi such that λ1 = 1, in such a way as to minimise the leading term. Then choose R = Y c for
c < 12 . Check that for any > 0, we have λd d . Then
X
|λd1 λd2 | ≤ R2+2 = Y 2c(1+) .
d1 d2
→
−
Choose < 1/2c − 1, then Y 2c(1+) Y / log Y . Write λ = (λ1 , λ2 , . . . ), so
→
− X λd λd (d1 , d2 )
1 2
Q λ = .
d1 d2
d1 ,d2 ≤R
→−
Want to minimise this subject to λ1 = 1. Want to diagonalise Q λ . Use, a slight variant of, Möbius
P P
inversion. For any m, m = d|m Φ (d). Take m = (d1 , d2 ). Then (d1 , d2 ) = δ|(d1 ,d2 ) Φ (δ), so
2
→
− X λd λd (d1 , d2 ) X X λd
1 2
Q λ = = Φ (δ) ,
d1 d2 d
d1 ,d2 ≤R δ≤R δ|d, d≤R
P
by using that δ | d1 and δ | d2 if and only if δ | d1 d2 / (d1 , d2 ). Set uδ = δ|d, d≤R λd /d. Then
→− X
Q λ = Φ (δ) u2δ .
δ≤R
Lecture 30
Claim that Wednesday
λd X δ
= µ uδ . (8) 12/12/18
d d
d|δ, δ≤R
44
M3P14 Number Theory 13 The distribution of prime numbers
So
→
− X 1 X µ (δ)2
Q λ = Φ (δ) u2δ ≥ , D= .
D Φ (δ)
δ≤R δ≤R
Equality holds when uδ = µ (δ) /DΦ (δ). We are going to show that D ≥ log R + O (1). Since R = Y c , this
gives us a leading term of
Y Y 1 Y
= = .
log R log Y c c log Y
1
c< 2 implies that 1/c > 2, so
X µ (δ)2 X 1
D= = .
Φ (δ) Φ (δ)
δ≤R δ≤R, δ squarefree
Need to show that Φ (d) d1− if d is squarefree, where Φ (d) = p|d (p − 1). If p is sufficiently large, then
Q
45