You are on page 1of 41

Quadratic Residues

Algebra

Aditya Khurmi

November 13, 2021

Aditya Khurmi Quadratic Residues November 13, 2021 1 / 41


Introduction

“Quadratic Residues” here is a short term for a fancy tree of concepts


and results that branch out from the simple idea of solving quadratic
equations modulo p.
We will first see what are quadratic residues, talk a bit about their
properties. But the focus of this session would mainly be on the idea of
“Legendre Symbol Manipulation”, which sadly is an idea I have mostly
seen in solutions to problems rather than one compiled resource which
makes it more accessible and common (like Vieta Jumping).

Aditya Khurmi Quadratic Residues November 13, 2021 2 / 41


Please note

We will mostly ignore p = 2 in our theorems (not definitions) unless


specified (as revenge for the time you missed this case on an Olympiad).
Also, one of the key themes of my books is to view the big picture (and
think combinatorially). The key theme here is going to be: think
algebraically!

Aditya Khurmi Quadratic Residues November 13, 2021 3 / 41


What are Quadratic Residues?

So what’s all the fuss about?


Definition
Let p be a prime. A number a is called a quadratic residue mod p if
there exists an integer x such that x2 ≡ a (mod p). It is called a
quadratic nonresidue otherwise. We use the shorthand QR to
denote a quadratic residue and NQR for a qudratic nonresidue.

This is in some sense finding out when a is defined modulo p.

Aditya Khurmi Quadratic Residues November 13, 2021 4 / 41


Simple Properties

Just like when a > 0, x2 = a has two solutions if a > 0, one solution if
a = 0, otherwise 0. Similarly show that
Lemma
If a ̸≡ 0 (mod p) is a quadratic residue, then x2 ≡ a (mod p) has two
solutions.

Aditya Khurmi Quadratic Residues November 13, 2021 5 / 41


How many Quadratic Residues?

The entire set of quadratic residues is given by

{12 , 22 , . . . , (p − 1)2 }.

When can two elements equal?

Aditya Khurmi Quadratic Residues November 13, 2021 6 / 41


Think algebraically!
If x2 ≡ y 2 (mod p), then the only possibility is x ≡ y or x ≡ −y
(mod p).

Aditya Khurmi Quadratic Residues November 13, 2021 7 / 41


Hence the set of all quadratic residues is
(  )
p−1 2

2 2
1 ,2 ,..., .
2

So there are (p − 1)/2 quadratic residues and hence (p − 1)/2 quadratic


nonresidues!

Aditya Khurmi Quadratic Residues November 13, 2021 8 / 41


Legendre’s Symbol

Now consider the question, is x a quadratic residue? How do we


convert this to an algebraic expression? We have the following
extremely useful notation
Definition
Let p be a prime, and x be an integer. Then we define the Legendre’s
notation as 
  
x 1 if x is a QR
= 0 if x ≡ 0 (mod p)
p 
−1 otherwise

Aditya Khurmi Quadratic Residues November 13, 2021 9 / 41


Sample Use: Fermat’s Christmas Theorem

The famous Fermat’s christmas theorem states for a prime p > 2, the
number −1 is a quadratic residue mod p if p ≡ 1 (mod p) and a
quadratic non-residue if p ≡ 3 (mod 4).
There’s a nice algebraic way to write this:
 
−1
= (−1)(p−1)/2 .
p

Aditya Khurmi Quadratic Residues November 13, 2021 10 / 41


Operations

As of now, the symbol isn’t very useful. When we define a function, we


often consider questions such as whether the function is additive,
multiplicative, bounded, involutive, etc.

Aditya Khurmi Quadratic Residues November 13, 2021 11 / 41


So let’s see how quadratic residues are related. Clearly if x, y are
quadratic residues, then xy is also a quadratic residue. However note
that we can’t say anything about x ± y. Hence let’s just think about
multiplication.

Aditya Khurmi Quadratic Residues November 13, 2021 12 / 41


Multiplication

Lemma
We have the following (remember that we are dealing with non-zero
residues)
1 QR × QR = QR;
2 QR × N QR = N QR;
3 N QR × N QR = QR.

The first one makes sense. The second one is slightly intuitive (because
it is similar to what holds for normal integers). The proof is easy too
(use the method of contradiction and multiply by an inverse).
What about the last case?

Aditya Khurmi Quadratic Residues November 13, 2021 13 / 41


This has a very fun combinatorial proof! Let X be the set of quadratic
residues and Y be the set of quadratic non-residues. Observe that
X ∪ Y = Fp . Further, |X| = |Y | and they are disjoint.
Pick any NQR n. Then nFp ≡ Fp (mod p) (weird notation but you get
the point). However, nX is the set Y (since a QR times a NQR is a
NQR), so nY must be congruent to the set X, and so we have our
result!

Aditya Khurmi Quadratic Residues November 13, 2021 14 / 41


Beautiful Result

So we have the following beautiful result:


Theorem (Legendre’s Symbol is completely multiplicative)
Let a, b be integers and p a prime. Then
    
a b ab
= .
p p p

Aditya Khurmi Quadratic Residues November 13, 2021 15 / 41


Legendre Symbol Manipulation

So what does this scary sounding topic really mean? At its heart, it
basically means: convert everything to algebra! The Legendre symbol
was our first step in doing that.
They key result we will use to change the new notation to algebra is
Euler’s theorem:  
a
≡ a(p−1)/2 (mod p)
p

Aditya Khurmi Quadratic Residues November 13, 2021 16 / 41


Wait, what?

Why is this result true?

Aditya Khurmi Quadratic Residues November 13, 2021 17 / 41


Proof

Firstly observe that this is true if a ≡ 0 or a is a QR, since then for


some x,
a(p−1)/2 ≡ (x2 )(p−1)/2 ≡ xp−1 ≡ 1 (mod p).
What about the case when a is not a quadratic residue?

Aditya Khurmi Quadratic Residues November 13, 2021 18 / 41


Ignore X = 0. Observe that p | X p−1 − 1 = (X (p−1)/2 − 1)(X (p−1)/2 + 1).
Hence it divides one of these. Now there are (p − 1)/2 numbers for
which it divides the first factor (namely all quadratic residues).
Since there are just p − 1 non-zero numbers mod p, and degree
X (p−1)/2 − 1 is (p − 1)/2, it feels like X (p−1)/2 ≡ 1 (mod p) can’t have
any other roots. So all the other remainders (NQRs) are roots of
X (p−1)/2 + 1 ≡ 0 (mod p), and we are done.

Aditya Khurmi Quadratic Residues November 13, 2021 19 / 41


Note 1

The degree part was slightly sloppy. In reality, we can’t easily bound
the number of roots of polynomials in fields. However, Lagrange’s
theorem tells us this is possible here. To read more about it, you can
refer to the section “Lagrange’s Theorem” on page 153 of the book.

Aditya Khurmi Quadratic Residues November 13, 2021 20 / 41


Note 2

We can also prove the result using primitive roots, where we have the
following incredible result:
Lemma (Primitive Roots and Quadratic Residues)
Let g be a primitive root modulo p. Then for any a ̸≡ 0 (mod p), write
a = g k . Then a is a quadratic residue if and only if k is even.

Problem
Show that the Legendre’s symbol is multiplicative using Euler’s theorem.

Aditya Khurmi Quadratic Residues November 13, 2021 21 / 41


Next result

The next result we will use is


Lemma
Let p > 2 be a prime. Then for any integer x,
(
−1 if p − 1 | x
1x + 2x + · · · + (p − 1)x ≡ (mod p).
0 otherwise

You can try and prove this (Hint: primitive roots).

Aditya Khurmi Quadratic Residues November 13, 2021 22 / 41


Application

Let’s prove this:


Lemma
If gcd(a, p) = 1 and p is an odd prime, then
p  
X an + b
= 0.
p
n=1

Aditya Khurmi Quadratic Residues November 13, 2021 23 / 41


Simple proof

Just observe that {an + b} is a complete set of residues mod p. So +1


and −1 pair up.

Aditya Khurmi Quadratic Residues November 13, 2021 24 / 41


Try this now

Now try this:


Lemma
Let p be an odd prime and a be an integer with gcd(a, p) = 1. Then
p  2 
X n +a
= −1.
p
n=1

The simple logic won’t work here.

Aditya Khurmi Quadratic Residues November 13, 2021 25 / 41


Let’s use Algebra!

Let’s use algebra on the first problem first. As suggested, we use


Euler’s
 result.
 Firstly, multiply by a−1 so we have to prove the problem
for n+cp . Here goes nothing: (w = (p − 1)/2)

p   p
X n+c X
≡ (n + c)w
p
n=1 n=1
p    
X
w w w−1 w
≡ n + n c + ··· + c (mod p)
1
n=1
p p p
!   ! !
X
w w X
w−1 w
X
0
≡ n + c n + ··· + c n
1
n=1 n=1 n=1
≡0 (mod p).

Aditya Khurmi Quadratic Residues November 13, 2021 26 / 41


Small catch

We evaulated the value mod p. So if S is the sum, then we just showed


that S ≡ 0 (mod p) not S = 0. But since −p ≤ S ≤ p (why?), this
gives us S ∈ {−p, 0, p}. I leave it to you to argue why S must equal 0.

Aditya Khurmi Quadratic Residues November 13, 2021 27 / 41


Quadratics

The same for quadratics:


p  2  p
X n +a X
S= ≡ (n2 + a)w
p
n=1 n=1
p    
X
p−1 w p−2 w
= n + n a + ··· + a
1
n=1

Again, pair up and use the lemma:


p p p
!   ! !
X w X X
S≡ np−1 + a np−3 + · · · + aw n0
1
n=1 n=1 n=1
≡ −1 (mod p)

Now do a similar analysis as before to conclude it must equal −1.


Aditya Khurmi Quadratic Residues November 13, 2021 28 / 41
General result

For general quadratics, a useful result we can obtain from this is:
Lemma
If a, b are not congruent, then
p  
X (n + a)(n + b)
= −1.
p
n=1

There’s also a result for a general quadratic an2 + bn + c, but we won’t


use it. If interested, you can look at Problem 8.4.2 on Page 220.

Aditya Khurmi Quadratic Residues November 13, 2021 29 / 41


Example Problem

Problem
Let p be an odd prime and let Fp denote (the field of ) integers modulo
p. How many elements are in the set

{x2 : x ∈ Fp } ∩ {y 2 + 1 : y ∈ Fp }?

Basically we want to find how many numbers a ∈ Fp are such that


(a, a + 1) is a pair of consecutive quadratic residues.

Aditya Khurmi Quadratic Residues November 13, 2021 30 / 41


Here’s the key question: how to convert this to an algebraic condition?

Aditya Khurmi Quadratic Residues November 13, 2021 31 / 41


Hint: Note that

 
a 2
 if a is a QR
+1= 1 if a ≡ 0 .
p 
0 otherwise

This can be used as a test whether a is a NQR.

Aditya Khurmi Quadratic Residues November 13, 2021 32 / 41


Observe that

 
a
 
a+1
 4
  if a, a + 1 are QRs > 0
+1 +1 = 2 if one of a, a + 1 ≡ 0
p p 
0 if any one of them is a NQR

So sum over to get the number.

Aditya Khurmi Quadratic Residues November 13, 2021 33 / 41


Explain why we have, if N is the number of solutions,
p−1         
X a a+1 −1
4N = +1 +1 +2+ 1+
p p p
a=0
p−1  2      !   
X a +a a a+1 −1
= + + +1 +2+ 1+
p p p p
a=0
 
−1
= −1 + p + 3 +
p
= p + 2 + (−1)(p−1)/2 .

Hence
1 
N = p + 2 + (−1)(p−1)/2 .
4

Aditya Khurmi Quadratic Residues November 13, 2021 34 / 41


Points on the circle x2 + y 2 ≡ 1 in Fp

Problem
Find the number of solutions to x2 + y 2 ≡ 1 (mod p).

Firstly, will this have > 0 solutions?

Aditya Khurmi Quadratic Residues November 13, 2021 35 / 41


Suppose p = 7 so that the QRs are {0, 1, 2, 4}. Hence, we can list all
possible values of x2 + y 2 (mod 7) as:

02 12 22 32 42 52 62
02 0 1 4 2 2 4 1
12 1 2 5 3 3 5 2
22 4 5 1 6 6 1 5
32 2 3 5 4 4 5 3
42 2 3 5 4 4 5 3
52 4 5 1 6 6 1 5
62 1 2 5 3 3 5 2

Note that this has 8 solutions. How do we find the number of solutions?

Aditya Khurmi Quadratic Residues November 13, 2021 36 / 41


Combinatorial idea: Look at 1 row at a time. So we fix y = c, and
want to find the number of solutions to x2 ≡ 1 − c2 ≡ a (mod p) where
a is some number in Fp .
As mentioned before, if x2 ≡ a (mod p) has 1 solution, it has two. If
a ≡ 0, then 1 solution. How do we write this algebraically?

Aditya Khurmi Quadratic Residues November 13, 2021 37 / 41


The number of solutions to x2 ≡ a (mod p) can be given by
 
a
1+ .
p

Now sum over all the rows.

Aditya Khurmi Quadratic Residues November 13, 2021 38 / 41


The number of solutions equal
p−1 p−1 
1 − c2 c2 − 1
   X 
X −1 p−1
1+ =p+ = p − (−1) 2
p p p
c=0 c=0

Voila!

Aditya Khurmi Quadratic Residues November 13, 2021 39 / 41


Problem to Try

Try this problem now:


Problem (Iran TST 2020/6)
p−1
p is an odd prime number and n = 2 . Find all n-tuples
(x1 , x2 , . . . , xn ) ∈ Fnp such that
n
X n
X n
X
xi ≡ x2i ≡ · · · ≡ xni (mod p).
i=1 i=1 i=1

The links to hints and the solution for this are on Page 227.

Aditya Khurmi Quadratic Residues November 13, 2021 40 / 41


Dirichlet’s amazing theorem

An amazing result by Dirichlet states that


Theorem
For a prime p ≡ 3 (mod 4), there are more quadratic residues in the
first half (1, (p − 1)/2) than the second half ((p + 1)/2, p − 1).

Since the number of quadratic residues equals to the number of


quadratic nonresidues, hence this is the same as saying that in the first
half, there are more quadratic residues than quadratic nonresidues.
This algebraically looks like
p−1
2  
X a
> 0.
p
a=0

Despite its simplicity, this has no known elementary proof.


Aditya Khurmi Quadratic Residues November 13, 2021 41 / 41

You might also like