M Mathematics Notes← Browse the course libraryOriginal PDF ↗
NUMBER THEORY

Elementary
Number Theory

From Bernoulli polynomials to partitions.
A browser-readable edition of PMath 340.

INSTRUCTORMichael Rubinstein
NOTES BYBenjamin Smith
TERMWinter 2006

Reading edition · Original wording retained. Some typography and page layout differ; consult the PDF for the authoritative typeset version.

This is based on a course by Michael Rubinstein (Winter 2006). All errors are the responsibility of the author.

1 Bernoulli Polynomials

The following three rules uniquely specify a sequence, Bn(t)B_n(t), of polynomials.

1. B0(t)=1B_0(t) = 1,

2. Bk′(t)=kBk−1(t)B_k'(t) = kB_{k-1}(t) for k≥1k\geq 1 (i.e. Bk(t)=∫0tBk−1(x)dx+Bk(0)B_k(t) = \int_0^tB_{k-1}(x)dx + B_k(0)), and

3. ∫01Bk(t)dt=0\int_0^1 B_k(t)dt = 0 for k≥1k\geq 1.

Proposition 1.1. For k≥0k\geq 0 Bk+1(t+1)−Bk+1(t)k+1=tk.\frac{B_{k+1}(t+1) - B_{k+1}(t)}{k+1} = t^k.

Proof. By induction on kk. When k=0k = 0, we have B1(t+1)−B1(t)=t+1+1−(t+1)=1=t0B_1(t+1) - B_1(t) = t+1 + 1 - (t + 1) = 1 = t^0. Suppose now that the result holds for some k>0k >0 so that Bk+1(t+1)−Bk+1(t)k+1=tk\frac{B_{k+1}(t+1) - B_{k+1}(t)}{k+1} = t^k. Now, Bk+2(t+1)−Bk+2(t)k+2=k+2k+2[∫0t+1Bk+1(x)dx−∫0tBk+1(x)dx]+Bk+2(0)−Bk+2(0)k+2=∫01Bk+1(x)dx⏟=0+∫1t+1Bk+1(x)dx−∫0tBk+1(x)dx=∫0tBk+1(u+1)du−∫0tBk+1(x)dx=∫0t(Bk+1(u+1)−Bk+1(u))du=∫0t(k+1)ukdu=tk+1\begin{align*} \frac{B_{k+2}(t+1) - B_{k+2}(t)}{k+2} &= \frac{k+2}{k+2}\left[\int_0^{t+1} B_{k+1}(x)dx - \int_0^tB_{k+1}(x)dx\right] + \frac{B_{k+2}(0) - B_{k+2}(0)}{k+2}\\ &=\underbrace{ \int_0^1B_{k+1}(x)dx}_{=0}+ \int_1^{t+1}B_{k+1}(x)dx - \int_0^tB_{k+1}(x)dx\\ &= \int_0^tB_{k+1}(u+1)du - \int_0^tB_{k+1}(x)dx\\ &= \int_0^t\left(B_{k+1}(u+1) - B_{k+1}(u)\right)du\\ &= \int_0^t (k+1)u^k du = t^{k+1} \end{align*} as claimed. ◻

Note that ∑i=1Nik=∑i=1N[Bk+1(i+1)−Bk+1(i)k+1]=1k+1(Bk+1(N+1)−Bk+1(1))\sum_{i=1}^Ni^k = \sum_{i=1}^N\left[\frac{B_{k+1}(i+1) - B_{k+1}(i)}{k+1}\right]= \frac{1}{k+1}\left(B_{k+1}(N+1) - B_{k+1}(1)\right)

We use Big-Oh notation to simplify by approximating upper bounds (this is less precise than asymptotic). We say that ff is asymptotically equivalent to gg as x→ax\to a if lim⁡x→af(x)g(x)=1\lim_{x\to a} \frac{f(x)}{g(x)} = 1 (denoted by f∼gf\sim g). Big-Oh notation is used as x→∞x\to \infty and we say f(x)=𝒪(g(x))f(x) = {\mathcal O}(g(x)) if there exists x0x_0 such that |f(x)|<cg(x)|f(x)| <cg(x) for some constant cc and for all x>x0x>x_0. Also f(x)f(x) is 𝒪(g(x){\mathcal O}(g(x) as x→ax\to a if |f(x)|<cg(x)|f(x)|<cg(x) for some cc fore all x∈Bϵ(a)x\in B_{\epsilon}(a).

1.1 Euler-Maclaurin summation formula

is a method to approximate sums involving integers.

For instance, one may ask how well does the integral ∫abg(x)dx\int_a^bg(x)dx approximate ∑n=a+1bg(n)\sum_{n = a+1}^bg(n)? First notice that, assuming g′g' exists and is continuous on [m,m+1][m,m+1], g(m+1)=∫mm+1g(t)dt+∫mm+1(t−m)g′(t)dt.g(m+1) = \int_m^{m+1}g(t)dt + \int_m^{m+1}(t-m)g'(t)dt. Indeed, integrating the second term by parts gives, ∫mm+1(t−m)g′(t)dt=[(t−m)g(t)]mm+1−∫mm+11⋅g(t)dt=g(m+1)−∫mm+1g(t)dt.\int_m^{m+1}(t-m)g'(t)dt = \left[(t-m)g(t)\right]_m^{m+1}- \int_m^{m+1}1\cdot g(t)dt = g(m+1) - \int_m^{m+1}g(t)dt. Here, for t∈[m,m+1]t\in [m,m+1] then t−mt-m is the fractional part of tt. This is also found using the floor function ⌊t⌋\lfloor t\rfloor which is the largest integer less than tt so that the fractional part of tt is given by {t}=t−⌊t⌋\{t\} = t - \lfloor t\rfloor. Hence, we may alternatively express the above as g(m+1)=∫mm+1g(t)dt+∫mm+1{t}g′(t)dt.g(m+1) = \int_m^{m+1}g(t)dt + \int_m^{m+1}\{t\}g'(t)dt.

Now, adding these up gives ∑m=a+1bg(m)=∫abg(t)dt+∫ab{t}g′(t)dt\sum_{m=a+1}^b g(m) = \int_a^bg(t)dt + \int_a^b\{t\}g'(t)dt where a,b∈ℤ,a<ba,b\in {\mathbb {Z}}, a<b and assuming that g′g' exists and is continuous on [a,b][a,b].

Further, ∫abg(t)dt+∫ab{t}g′(t)dt=∫abg(t)dt+12∫mm+1g′(t)dt+∫ab({t}−1/2)g′(t)dt=∫abg(t)dt+12[g(b)−g(a)]+∫abB1({t})g′(t)dt.\begin{align*} \int_a^bg(t)dt + \int_a^b\{t\}g'(t)dt &=\int_a^bg(t)dt +\frac{1}{2}\int_m^{m+1}g'(t)dt + \int_a^b(\{t\}-1/2)g'(t)dt\\ &=\int_a^b g(t)dt + \frac{1}{2}[g(b)-g(a)] + \int_a^bB_1(\{t\})g'(t)dt. \end{align*} and subtracting 1/21/2 makes B1({t})B_1(\{t\}) smaller.

The above is called a first order Euler-Maclaurin approximation. Now consider ∫abB1({t})g′(t)dt=∫aa+1B1({t})g′(t)dt+∫a+1a+2B1({t})g′(t)dt+⋯+∫b−1bB1({t})g′(t)dt\int_a^bB_1(\{t\})g'(t)dt = \int_a^{a+1}B_1(\{t\})g'(t)dt + \int_{a+1}^{a+2}B_1(\{t\})g'(t)dt+ \cdots + \int_{b-1}^bB_1(\{t\})g'(t)dt whose typical term, via integration by parts, is ∫mm+1B1({t})g′(t)dt=12[B2(t−m)g′(t)dt]mm+1−12∫mm+1B2(t−m)g″(t)dt=12[B2(1)g′(m+1)−B2(0)g′(m)]−12∫mm+1B2(t−m)g″(t)dt=B2(0)2[g′(m+1)−g′(m)]−12∫mm+1B2(t−m)g″(t)dt\begin{align*} \int_m^{m+1}B_1(\{t\})g'(t)dt & = \frac{1}{2}\left[B_2(t-m)g'(t)dt\right]_m^{m+1} - \frac{1}{2}\int_m^{m+1}B_2(t-m)g''(t)dt\\ &= \frac{1}{2}\left[B_2(1)g'(m+1) - B_2(0)g'(m)\right] -\frac{1}{2}\int_m^{m+1}B_2(t-m)g''(t)dt\\ &= \frac{B_2(0)}{2}[g'(m+1) - g'(m)] - \frac{1}{2}\int_m^{m+1}B_2(t-m)g''(t)dt\\ \end{align*} since Bk(1)=Bk(0)B_k(1) = B_k(0) for all k≥2k\geq 2. Now, inductively we can state the kthk^{th} order Euler-Maclaurin approximation as follows; Let a,b∈ℤa,b\in {\mathbb {Z}} with a<ba<b and g:ℝ→ℝg:{\mathbb {R}}\to {\mathbb {R}} so that g(k)g^{(k)} exists and is continuous on [a,b][a,b]. Then ∑m=a+1bg(m)=∫abg(t)dt+∑i=1k(−1)iBi(0)i![g(i−1)(b)−g(i−1)(a)]+(−1)k+1k!∫abBk({t})g(k)(t)dt.\boxed{\sum_{m=a+1}^bg(m) = \int_a^bg(t)dt + \sum_{i=1}^k \frac{(-1)^i B_i(0)}{i!}[g^{(i-1)}(b) - g^{(i-1)}(a)] + \frac{(-1)^{k+1}}{k!}\int_a^b B_k(\{t\})g^{(k)}(t)dt.}

1.2 Applications of Euler-Maclaurin approximation

Proposition 1.2 (Stirling’s formula for n!n!). n!≈(ne)n2πn.n!\approx \left(\frac{n}{e}\right)^n\sqrt{2\pi n}.

Proof. We have that log⁡n!=∑m=1nlog⁡m=∑m=2nlog⁡m\log n! = \sum_{m=1}^n \log m = \sum_{m=2}^n \log m which, by first order E-M approximation is ∑m=2nlog⁡m=∫1nlog⁡(t)dt+12[log⁡n−log⁡1]+∫1n[{t}−1/2t]dt=[tlog⁡t−t]1n+log⁡n2+∫1n{t}−1/2tdt=nlog⁡n−n+1+log⁡n2+∫1n{t}−1/2tdt\begin{align*} \sum_{m=2}^n \log m &= \int_1^n \log (t) dt + \frac{1}{2}[\log n - \log 1] + \int_1^n \left[\frac{\{t\} - 1/2}{t}\right]dt\\ &= [t\log t - t]_1^n + \frac{\log n}{2} + \int_1^n \frac{\{t\}- 1/2}{t} dt\\ &= n\log n - n +1 + \frac{\log n}{2} + \int_1^n \frac{\{t\}- 1/2}{t} dt\\ \end{align*} so that log⁡n!−(nlog⁡n−n+1+12log⁡n)=1+∫1n{t}−1/2tdt=H.W.constant+𝒪(1/n).\log n! - (n\log n - n +1 + \tfrac{1}{2}\log n)= 1+ \int_1^n \frac{\{t\}- 1/2}{t} dt \stackrel{H.W.}{=} \text{constant} + {\mathcal O}(1/n).

Hence, in the limit, limn→∞[logn!−nlogn−n+1+12logn]=C1\lim_{n\to \infty} \left[\log n! - n\log n - n +1 + \tfrac{1}{2}\log n\right] = C_1 and the exponential of this is lim⁡n→∞n!enlog⁡n−n+1/2log⁡n=C\lim_{n\to \infty}\frac{n!}{e^{n\log n - n + 1/2\log n}} = C. That is limn→∞n!nne−nn=C\lim_{n\to \infty} \frac{n!}{n^n e^{-n}\sqrt{n}} = C or that n!≈(ne)nn⋅Cn! \approx \left(\frac{n}{e}\right)^n\sqrt{ n}\cdot C.

The constant CC here is called Euler’s constant and is discussed next. ◻

1.3 Euler’s constant

Consider the sum ∑m=1n1m\sum_{m=1}^n \frac{1}{m} which diverges as N→∞N\to \infty, but how quickly? Writing 1+∑m=2N1/m1 + \sum_{m=2}^N1/m so not to integrate near zero. Then 1+∑m=2N1/m=1+∫1Ndtt+12[1N−11]−∫1N{t}−1/2t2dt=log⁡N+12+12N−[∫1∞{t}−1/2t2dt−∫N∞{t}−1/2t2dt].\begin{align*} 1 + \sum_{m=2}^N1/m &= 1 + \int_1^N \frac{dt}{t} + \frac{1}{2}\left[\frac{1}{N} - \frac{1}{1}\right] - \int_1^N \frac{\{t\}-1/2}{t^2}dt\\ &= \log N + \tfrac{1}{2} + \tfrac{1}{2N} - \left[\int_1^{\infty} \frac{\{t\}- 1/2}{t^2}dt - \int_N^\infty \frac{\{t\}- 1/2}{t^2}dt\right]. \end{align*} Examining the bracketed terms one finds that ∫1∞{t}−1/2t2\int_1^\infty \frac{\{t\}-1/2}{t^2} is constant by comparison with ∫1∞1t2dt\int_1^\infty \frac{1}{t^2}dt and, furthermore, that |∫N∞{t}−1/2t2dt|≤12∫N∞1t2dt=𝒪(1/n)\left|\int_N^\infty \frac{\{t\}-1/2}{t^2}dt\right|\leq \frac{1}{2}\int_N^\infty\frac{1}{t^2}dt = {\mathcal O}(1/n). Hence then, the above evaluates as log⁡N+12+12N−C+𝒪(1/N)=log⁡N+γ+𝒪(1/N)\log N + \tfrac{1}{2} + \tfrac{1}{2N} - C + {\mathcal O}(1/N) = \log N + {\gamma}+ {\mathcal O}(1/N) where γ=0.5772…{\gamma}= 0.5772\dots is Euler’s constant.

Exercise 1.3. Prove that

  1. B1({t})={t}−1/2=−1π∑m=1∞sin⁡(2πm+t)m=−1π∑m≠0e2πimt2πimB_1(\{t\}) = \{t\} - 1/2 = - \frac{1}{\pi}\sum_{m=1}^\infty \frac{\sin(2\pi m + t)}{m} = \frac{-1}{\pi} \sum _{m\neq 0} \frac{e^{2\pi i m t}}{2\pi i m} for t∉ℤt\notin {\mathbb {Z}} and

  2. Bk({t})=−k!∑m≠0e2πimt(2πim)kB_k(\{t\}) = - k! \sum_{m\neq 0} \frac{e^{2\pi i mt}}{(2\pi i m )^k} for t∈ℝ,k≥2t\in {\mathbb {R}}, k\geq 2.

Bk({t})B_k(\{t\}) is continuous and even at t∈ℤt\in {\mathbb {Z}}. B2(1)=B2(0)B_2(1) = B_2(0), plugging in t=0t = 0, let k=2k0k = 2k_0 with k0≥1k_0\geq 1. Now B2k0(0)=(−2k0)!∑m=−∞,≠0∞1(2π)2k0(−1)k0m2k0B_{2k_0}(0) = (-2k_0)!\sum_{m = -\infty, \neq 0}^\infty \frac{1}{(2\pi)^{2k_0}(-1)^{k_0}m^{2k_0}} so ∑m=1∞1m2k0=(−1)k0+1(2π)2k0(2k0)!12B2k0(0).\boxed{\sum_{m=1}^\infty \frac{1}{m^{2k_0}}= \frac{(-1)^{k_0+1}(2\pi)^{2k_0}}{(2k_0)!}\frac{1}{2}B_{2k_0}(0)}. For example, if k0=1k_0 = 1 this is ∑m=1∞1m2=(2π)22!12B2(0)=π2B2(0)=π2/6\sum_{m=1}^\infty \frac{1}{m^2} = \frac{(2\pi)^2}{2!}\frac{1}{2}B_2(0) = \pi^2 B_2(0) = \pi^2/6 and if k0=2k_0 = 2 we have ∑m=1∞1m4=π490.\sum_{m=1}^\infty \frac{1}{m^4} = \frac{\pi^4}{90}.

2 Divisibility and primes

For integers a,b∈ℤa,b\in {\mathbb {Z}}, then aa is said to be divide bb if b=mab = ma for some m∈ℤm\in {\mathbb {Z}}. This is also written as a|ba|b. Note that 0|00|0 and 4|04|0 but 00 does not divide 44.

Some properties of divisibility are as follows; for a,b,c∈ℤa,b,c\in {\mathbb {Z}}

  1. If a|ba|b and b|cb|c then a|ca|c (this is transitivity)

  2. If a|ba|b and b|cb|c then a|bx+cya|bx+cy for all x,y∈ℤx,y\in {\mathbb {Z}}

  3. If a|ba|b and b|ab|a then a=±ba = \pm b

  4. if a|ba|b and b≠0b\neq 0 then |a|≤|b||a|\leq |b|

An integer p∈ℤp\in {\mathbb {Z}} is said to be prime if its only positive divisors are 1 and pp. Otherwise, pp is said to be composite.

Lemma 2.1. Any integer n>1n>1 is either prime, or a product of primes.

Proof. By induction on nn, this is true for n=2n = 2 which is prime. Now assuming the result holds for all integers up to n−1n-1 and consider nn. If nn is prime, we are done. Otherwise nn is not prime so there exists a positive divisor say a≠1a\neq 1. Now n=abn = ab for some b∈ℤb\in {\mathbb {Z}} and we have that both 1<a,b<n1<a,b<n. Now, by induction hypothesis, aa and bb are either prime or can be expressed as a product of primes. Thus, nn can be expressed as a product of primes. ◻

Theorem 2.2. There are infinitely many primes.

Proof. Let 2,3,5,7,⋯,p2,3,5,7, \cdots, p be a list of primes ≤p\leq p. Consider N:=(2⋅3⋅5⋯p)+1N := (2\cdot 3\cdot 5\cdots p) + 1. If 2 divides NN then 2|N−(2⋅3⋅5⋯p)=12|N- (2\cdot 3\cdot 5\cdots p) = 1 which is not true. So 2|̸N2\not | N Likewise, 3,5,7,⋯,p3,5,7, \cdots, p do not divide NN. Our lemma implies that either NN is prime or can be written as a product of primes, so there must be another prime in our list and this can always be done so there are infinitely many primes. ◻

2.1 Unique factorization

Lemma 2.3. Let m∈ℤm\in {\mathbb {Z}} be ≥2\geq 2. Assume that mm is uniquely expressible as a product of primes. If p|mp|m with pp prime, then pp must appear in the factorization of mm.

Proof. Let p|mp|m so that m=p⋅bm = p\cdot b for some b∈ℤb\in {\mathbb {Z}}. bb is either prime, or expressible as a product of primes say b=q1⋯qkb = q_1\cdots q_k with each qiq_i prime. So now m=pq1q2⋯qkm = pq_1q_2\cdots q_k is a unique factorization of mm into primes which includes pp. ◻

Corollary 2.4. If m≥2m\geq 2 is uniquely expressible as a product of primes with p|mp|m and p′|mp'|m (p≠p′p\neq p'), then pp′pp' must appear in the factorization of mm.

Theorem 2.5 (Unique factorization of integers). Every n∈ℤn\in {\mathbb {Z}} (n≥2n\geq 2) is uniquely expressible as a product of primes.

Proof. By induction; this hold for n=2n = 2 which is prime. Now assuming the result holds for all numbers up to n−1n-1 and consider the nthn^{th} case. Assume that nn has two distinct factorizations say n=p1⋯pk=p1′⋯pk2′n = p_1\cdots p_k = p_1' \cdots p_{k_2}' where all the pi,pj′p_i, p_j' are prime and none of the primes on the left occur on the right (if so we could cancel). Without loss of generality p1≤p2≤⋯≤pkp_1\leq p_2\leq \cdots \leq p_k and p1′≤⋯≤pk2′p_1'\leq \cdots \leq p_{k_2}'. We can assume nn is composite since if it were prime, it would already be uniquely factorized. So both k,k2≥2k, k_2\geq 2 and p12,p1′2≤np_1^2, p_1'^2\leq n. Also assume without loss of generality that p1<p1′p_1<p_1' so p1≤p1′−1p_1\leq p_1'-1.

Now, p1p1′≤(p1′−1)p1′=p1′2−p1′≤n−2p_1p_1' \leq (p_1'-1)p_1' = p_1'^2 - p_1'\leq n-2 and hence 2≤n−p1p1′<n2\leq n- p_1p_1'< n. by induction hypothesis n−p1p1′n- p_1p_1' is uniquely factorable and p1|np_1|n so p1|n−p1p1′p_1 | n - p_1p_1'. Also then p1′|n−p1p1′p_1'|n - p_1p_1' so our corollary (along with divisibility properties) implies that p1p1′|np_1p_1'|n meaning that n=p1p1′bn = p_1p_1'b for some b∈ℤb\in {\mathbb {Z}}. Let b=q1⋯qlb = q_1\cdots q_l (be a product of primes) and now n=p1p2⋯pk=p1p1′q1⋅qln = p_1p_2\cdots p_k = p_1p_1' q_1\cdot q_l allowing us to cancel p1p_1 and have two distinct factorizations of n/p1<nn/p_1<n (contradicting the induction hypothesis). ◻

2.2 Application of unique factorization

Let d(n)d(n) denote the number of divisors of nn (positive). If n=p1α1⋯pkαkn = p_1^{{\alpha}_1}\cdots p_k^{{\alpha}_k} then d(n)=(α1+1)⋯(αk+1).d(n) = ({\alpha}_1+1) \cdots ({\alpha}_k+1). Now let σ(n){\sigma}(n) denote the sum of the positive divisors of nn. Then σ(n)=∏i=1k(∑j=0αipij).\begin{equation} \label{sigma}{\sigma}(n) = \prod_{i = 1}^k\left(\sum_{j = 0}^{{\alpha}_i} p_i^j\right). \end{equation}(1)

A map f:ℤ>0→ℂf:{\mathbb {Z}}_{>0}\to {\mathbb {C}} is said to be multiplicative if f(ab)=f(a)f(b)f(ab) = f(a) f(b) whenever gcd⁡(a,b)=1\gcd(a,b) = 1. Note that both d(n)d(n) and σ(n){\sigma}(n) are multiplicative.

Indeed, let n=∏i=1kpiαi,m=∏i=1lqiβin = \prod_{i=1}^k p_i^{{\alpha}_i}, m = \prod_{i=1}^l q_i^{{\beta}_i} be such that gcd⁡(m,n)=1\gcd(m,n) = 1. Then σ(nm)=σ(∏i=1kpiαi∏i=1lqiβi)=∏a=1k(∑j=0kpaαj)∏b=1l(∑j=0lqbβj)=σ(n)σ(m).{\sigma}(nm) ={\sigma}\left(\prod_{i=1}^k p_i^{{\alpha}_i}\prod_{i=1}^l q_i^{{\beta}_i}\right) = \prod_{a = 1}^k\left(\sum_{j=0}^k p_a^{{\alpha}_j}\right)\prod_{b=1}^l\left(\sum_{j=0}^l q_b^{{\beta}_j} \right) = {\sigma}(n) {\sigma}(m).

Observe that this does not hold when gcd⁡(m,n)≠1\gcd(m,n) \neq 1 (e.g. σ(25)≠σ(5)σ(5){\sigma}(25)\neq {\sigma}(5){\sigma}(5)).

A perfect number nn is a positive integer whose proper divisors sum to itself (i.e. σ(n)=2n{\sigma}(n) = 2n). The first two perfect numbers are 6 and 28.

Theorem 2.6.

  1. Euclid proved that if n=2k−1pn = 2^{k-1}p with k≥2k\geq 2 and p=2k−1p = 2^k -1 is prime, then nn is perfect.

  2. Euler proved that if nn is even and perfect then it is of the form 2k−1p2^{k-1}p with p=2k−1p = 2^k -1 prime.

Proof.

  1. Let n=2k−1pn = 2^{k-1}p with pp an odd prime of the form 2k−12^k -1. Then σ(n)=σ(2k−1)σ(p)=(1+2+⋯+2k−1)(1+p)=2k−12−1(1+2k−1)=(2k−1)2k=2n\begin{align*} {\sigma}(n) = {\sigma}(2^{k-1}){\sigma}(p)&= (1 + 2+ \cdots + 2^{k-1})(1+p)\\ &= \frac{2^k-1}{2-1}(1+2^k-1) = (2^k-1)2^k = 2n \end{align*}

  2. Let nn be even and perfect (so that n=2m⋅n0n = 2^m\cdot n_0 with n0n_0 odd and m≥1m\geq 1). Consider now, σ(n)=σ(2m)σ(n0)=(2m+1−1)σ(n0)=2(2m⋅n0)=2m+1n0{\sigma}(n) = {\sigma}(2^m) {\sigma}(n_0) = (2^{m+1}-1){\sigma}(n_0) = 2(2^m\cdot n_0) = 2^{m+1}n_0 since nn is perfect. 2m+1−12^{m+1}-1 is odd so by unique factorization theorem, 2m+1|(2m+1−1)σ(n0)2^{m+1}|(2^{m+1}-1){\sigma}(n_0) which implies 2m+1|σ(n0)2^{m+1}|{\sigma}(n_0). Thus σ(n0)=2m+1s{\sigma}(n_0) = 2^{m+1}s for some s∈ℤs\in {\mathbb {Z}} so (2m+1−1)2m+1s=2m+1n0(2^{m+1}-1)2^{m+1}s = 2^{m+1}n_0 and hence s|n0s|n_0. Simplifying the previous equation says 2m+1s=n0+s2^{m+1}s = n_0 + s and we know σ(n0)=2m+1s{\sigma}(n_0) = 2^{m+1}s which suggests1 that nn has two divisors. Hence nn is prime and s=1s = 1. Hence n0=2m+1−1n_0 = 2^{m+1}-1 (prime) and this verifies our claim.

 ◻

Primes of the form 2k−12^k-1 are called Mersenne primes however not all numbers of this form are prime. In fact, it remains an unsolved problem to verify whether or not there are infinitely many Mersenne primes (there probably are). Furthermore, none knows if there are any odd perfect numbers (probably not).

Theorem 2.7 (Division/Euclidean algorithm). Let a,b∈ℤa,b\in {\mathbb {Z}} with b>0b>0, then there exist unique integers q,rq,r with 0≤r<b0\leq r<b such that a=qb+ra = qb+r.

Proof. Let S={a−kb:k∈ℤ}S= \{a - kb:k\in {\mathbb {Z}}\} and T={m∈S:m≥0}T = \{m\in S:m\geq 0\}. Observe first that TT is non empty because a−kb≥0a-kb\geq 0 whenever k≤a/bk\leq a/b so infinitely many kk work. Now, TT is comprised of non-negative integers and any non-empty set of non-negative integers has a minimal element (this is by the well-ordering principal which is equivalent to the axiom of choice). Let rr be the minimal element in TT and qq the corresponding kk. By these means, we have that a−qb=ra - qb = r with r≥0r\geq 0. We seek to show that r<br<b, so assume for the moment that r≥br\geq b. If this were the case, then r−b=a−(q+1)b>0r-b = a-(q+1)b>0 and is in SS so a−(q+1)b)∈Ta-(q+1)b)\in T and is smaller than rr (contradicting minimality of rr).

We have non shown existence of qq and rr but remain to verify the uniqueness. For this, suppose that a=q1b+r1=q2b+r2a = q_1b+r_1 = q_2b+r_2 with both 0≤r1,r2<b0\leq r_1,r_2<b. Equivalently, then 0=(q1−q2)b+(r1−r2)0 = (q_1-q_2)b + (r_1-r_2) which implies (q2−q1)b=(r1−r2)(q_2-q_1)b = (r_1-r_2) and hence b|(r1−r2)b|(r_1-r_2). However, −b<−r2≤r1−r2≤r1<b-b<-r_2\leq r_1-r_2\leq r_1<b so r1−r2=0r_1-r_2 = 0 which implies r1=r2r_1 = r_2 and q1=q2q_1 = q_2 hence, uniqueness. ◻

Let a,b∈ℤa,b\in {\mathbb {Z}}, an integer cc is called a common divisor of aa and bb if both c|ac|a and c|bc|b. Define the gcd⁡(a,b)\gcd(a,b) to be the greatest common divisor of aa and bb

2.3 Euclidean Algorithm

This algorithm is used to find the greatest common divisor of two integers and is essentially a repeated division algorithm until the remainder is zero. We claim that remainders are strictly decreasing, non-negative and hence must reach 0. Furthermore, the gcd⁡(a,b)\gcd(a,b) is preserved on every line.

Indeed, let d=gcd⁡(a,b)d = \gcd(a,b) so that d|a,bd|a, b hence d|a−qb=rd|a-qb = r so that dd is a common divisor of both bb and rr. To see that it is furthermore the greatest common divisor of bb and rr, let cc be any other common divisor and show c≤dc\leq d. We have c|bc|b and c|rc|r so c|qb+r=ac|qb+r = a, hence cc is a common divisor of bb and aa so is ≤d\leq d.

Lemma 2.8. If d=gcd⁡(a,b)d = \gcd(a,b) then there exist x,y∈ℤx,y\in {\mathbb {Z}} such that d=ax+byd = ax + by (and any multiple of dd).

This follows from back substitution of the Euclidean algorithm

Example 2.9. Let a=527,b=153a = 527, b= 153. Then 527=3⋅153+68153=2⋅68+1768=4⋅17+0\begin{align*} 527 &= 3\cdot 153 + 68\\ 153 &= 2\cdot 68+17\\ 68 &= 4\cdot 17 + 0 \end{align*} so gcd⁡(a,b)=17\gcd(a,b) = 17 and applying this algorithm backwards, we get 17=153−2⋅68=153−2(527−3⋅153)=7⋅153−2⋅527.17 = 153- 2\cdot 68 = 153 - 2(527 - 3\cdot 153) = 7 \cdot 153 - 2\cdot 527.

Theorem 2.10. Let a,b,c∈ℤa,b,c\in {\mathbb {Z}} and assume that a|bca|bc but gcd⁡(a,b)=1\gcd(a,b) = 1. Then a|ca|c

Proof. gcd⁡(a,b)=1\gcd(a,b) = 1 implies that there exist x,y∈ℤx,y\in {\mathbb {Z}} such that ax+by=1ax + by = 1. Multiplying this by cc gives acx+bcy=cacx + bcy = c. Now a|aca|ac and a|bca|bc (by assumption) so a|acx+bcy=ca|acx + bcy = c as required. ◻

Corollary 2.11. Let pp be prime b,c∈ℤb,c\in {\mathbb {Z}} and let p|bcp|bc. If p|̸bp\not |b then p|cp|c. Furthermore, if p|b1b2B−3⋯bkp|b_1b_2B-3\cdots b_k then p|bip|b_i for some ii.

Proof. If p|̸bp\not| b then gcd⁡(p,b)=1\gcd(p,b) = 1 and this is precisely the conditions required from the previous theorem. ◻

With these results, one may provide an inductive proof of the unique factorization theorem as follows; Suppose n≥2n\geq 2 has two distinct factorizations p1⋯pk=p1′⋅pl′p_1\cdots p_k = p_1'\cdot p_l'. We have p1|n=p1′⋯pl′p_1 |n = p_1'\cdots p_l' so then p1|pj′p_1|p_j' for some jj. This implies p1=pj′p_1 = p_j' so they may be canceled. Repeating this indefinitely one finds that all of the prime factors of nn coincide and we are done.

One may apply unique factorization to give Euler’s proof that there are infinitely many primes. Let s>1s>1 and consider ∑n=1∞1ns=1+12s+13s+⋯=∏∀p(1+1ps+1p2s+⋯).\sum_{n=1}^\infty \frac{1}{n^s}= 1+ \frac{1}{2^s} + \frac{1}{3^s} + \cdots = \prod_{\forall p} \left(1 + \frac{1}{p^s} + \frac{1}{p^{2s}} + \cdots \right). By unique factorization, every n∈ℕn\in {\mathbb {N}} appears exactly once and his series is absolutely convergent since s>0s>0 so rearranging sums is valid. Hence, ∑n=1∞1ns=∏∀p(1+1ps+1p2s+⋯)=∏∀p11−1/ps.\sum_{n=1}^\infty \frac{1}{n^s} = \prod_{\forall p} \left(1 + \frac{1}{p^s} + \frac{1}{p^{2s}} + \cdots \right) = \prod_{\forall p} \frac{1}{1-1/p^s}. Now, Euler substitutes the value s=1s= 1 so that the left hand side diverges (as the Harmonic series), so the right hand side must have infinitely many factors (in order to diverge).

How many primes are there? Let π(x)\pi(x) denote the number of primes ≤x\leq x. For example, π(106)=78498\pi(10^6) = 78498.

Gauss conjectured that at xx, the average gap size between primes is approximately log⁡x\log x. That is to say the density of primes near xx is 1log⁡x\frac{1}{\log x}, so Gauss conjectured that π(x)≈∫2xdtlog⁡t=xlog⁡x\pi(x) \approx \int_2^x \frac{dt}{\log t} = \frac{x}{\log x} so that π(x)≈xlog⁡x\pi(x)\approx \frac{x}{\log x}. This was proven in 1896.

2.4 Riemann Hypothesis

π(x)=∫2xdtlog⁡t+𝒪(x1/2log⁡x)=xlog⁡x+𝒪(xlog⁡x).\boxed{\pi(x) = \int_2^x \frac{dt}{\log t} + {\mathcal O}(x^{1/2}\log x) = \frac{x}{\log x} + {\mathcal O}(\sqrt{x}\log x).} To demonstrate an example, we have π(1013)=346,065,536,839\pi(10^{13}) = 346,065,536,839 and 1013log⁡1013=108971\frac{10^{13}}{\log 10^{13}} = 108971.

2.5 Congruences

Let a,b,m∈ℤa,b,m\in {\mathbb {Z}} with m≥1m\geq 1. we say that aa is congruent to bb modulo mm (i.e. a≡bmod⁡ma\equiv b\mod m) if m|a−bm|a-b. Note that a≡bmod⁡ma\equiv b \mod m if and only if they both have the same remainder when divided by mm. Indeed, let a=km+ra = km + r and b=lm+sb = lm + s with 0≤r,s<m0\leq r,s< m. If r=sr = s then m|a−b=(k−l)mm|a-b = (k-l)m and if m|a−b=(k−l)m+(r−s)m |a-b = (k-l)m + (r-s) then also m|r−sm|r-s so r−s=c⋅mr-s = c\cdot m for some integer cc, but the constraint that 0≤r,s<m0\leq r,s<m implies c=0c = 0 so r=sr = s.

Note that the only possible remainders modulo mm are 0,1,2,…,m−10,1,2, \dots, m-1 and these integers form a complete set of residues (i.e. any integer is congruent to exactly one of these (modulo mm).

Lemma 2.12. Congruence is an equivalence relation (i.e. 1. a≡amod⁡ma\equiv a\mod m 2. if a≡bmod⁡ma\equiv b\mod m then b≡amod⁡mb\equiv a\mod m and 3. if a≡bmod⁡ma\equiv b \mod m and b≡cmod⁡mb\equiv c\mod m then a≡cmod⁡ma\equiv c\mod m).

Proof. We only prove 3. If a≡bmod⁡ma\equiv b\mod m and b≡cmod⁡mb\equiv c\mod m then m|a−cm|a-c and m|b−cm|b-c so m|a−b+b−c=a−cm|a-b+b-c = a-c as required. ◻

Lemma 2.13. Let a≡a′mod⁡ma\equiv a'\mod m and b≡b′mod⁡mb\equiv b'\mod m then a+b≡a′+b′mod⁡ma+ b \equiv a'+b'\mod m and ab≡a′b′mod⁡mab\equiv a'b'\mod m.

Proof. This is trivial from definition (i.e. tautological). ◻

The addition rule for congruence classes holds and includes subtraction. What about division? We check if ca≡cbmod⁡mca\equiv cb\mod m then m|c(a−b)m|c(a-b) and if gcd⁡(c,m)=1\gcd(c,m) = 1 then m|a−bm|a-b so a≅bmod⁡ma\cong b \mod m. However, if gcd⁡(c,m)≠1\gcd(c,m)\neq 1 then we may not have division.

For example, 3⋅1≡3⋅3mod⁡63\cdot 1\equiv 3\cdot 3 \mod 6 but 1≢3mod⁡61\not\equiv 3\mod 6.

2.6 Application of arithmetic in congruence classes

How can one tell if an integer is divisible by 9? Write n=∑k=0Nak⋅10kn =\sum_{k=0}^N a_k\cdot 10^k with each ai∈{0,…,9}a_i\in \{0, \dots, 9\}. Now, since 10≡1mod⁡910\equiv 1\mod 9 then n≡∑k=0Nakmod⁡9n \equiv \sum_{k=0}^Na_k \mod 9. Hence, 9|n if and only if 9|∑k=0Nak.9|n \, \text{ if and only if }\, 9|\sum_{k=0}^Na_k.

2.7 Inverses modulo mm

Let m∈ℤm\in {\mathbb {Z}}, m≥1m\geq 1. An element a∈ℤa\in {\mathbb {Z}} is said to have an inverse modulo mm if there exists b∈ℤb\in {\mathbb {Z}} such that a⋅b≡1mod⁡ma\cdot b\equiv 1\mod m. If such a bb exists, it is denoted by a−1a^{-1}.

Lemma 2.14. aa is invertible modulo mm if and only if gcd⁡(a,m)=1\gcd(a,m) =1.

Proof. If aa is invertible mod⁡m\mod m then there exists b∈ℤb\in {\mathbb {Z}} such that ab≡1mod⁡mab\equiv 1 \mod m so that m|ab−1m|ab-1 meaning ab−1=kmab-1 = km for some k∈ℤk\in {\mathbb {Z}}. Let d=gcd⁡(a,m)d = \gcd(a,m) so d|ad|a and d|md|m hence d|ab−km=1d|ab-km = 1. Thus d=1d = 1.

Conversely, if gcd⁡(a,m)=1\gcd(a,m) = 1 so there exists x,y∈ℤx,y\in {\mathbb {Z}} such that ax+my=1ax + my = 1 (by Euclidean algorithm) so ax−1=myax - 1 = my which means m|ax−1m|ax-1 and thus ax≡1mod⁡max \equiv 1\mod m. ◻

Example 2.15. Find 20−1mod⁡9320^{-1} \mod 93. Applying the Euclidean algorithm; 93=4⋅20+1320=1⋅13+713=1⋅7+67=1⋅6+16=6⋅1+0\begin{align*} 93 &= 4\cdot 20 + 13\\ 20 &= 1\cdot 13 + 7 \\ 13&= 1\cdot 7 + 6\\ 7 &= 1\cdot 6 + 1\\ 6 & = 6\cdot 1 +0 \end{align*} Now, back substitution gives 1=7−1⋅6=7−(13−7)=2⋅7−13=2(20−13)−13=2(20)−3⋅13=2(20)−3(93−4⋅20)=14(20)−3(93)\begin{align*} 1 &= 7-1\cdot 6\\ &= 7 - (13-7) \\ &= 2\cdot 7 - 13\\ &= 2(20-13) - 13\\ &=2(20)- 3\cdot 13\\ &=2(20) - 3(93-4\cdot 20)\\ &= 14(20) - 3(93) \end{align*} so 20−1=14.20^{-1} = 14.

Another further application of this allows us to solve linear congruences modulo mm. For example, solve 20x≡7mod⁡9320x \equiv 7 \mod 93. Multiplying by 20−1=1420^{-1} = 14 gives x≡14⋅7≡5mod⁡93x \equiv 14\cdot 7 \equiv 5\mod 93. Note that ax≡bmod⁡max\equiv b\mod m is called a linear congruence.

alternative proof for inverses;. Let gcd⁡(a,m)=1\gcd(a,m) = 1. and consider the set of integers 0⋅a,1⋅a,…,(m−1)⋅a0\cdot a, 1\cdot a, \dots, (m-1)\cdot a. These are all distinct modulo mm so one of them must be congruent to 11 modulo mm. Indeed, for two to be equal (mod mm) then b1a≡b2amod⁡mb_1a\equiv b_2a\mod m so that m|a(b1−b2)m|a(b_1-b_2), but gcd⁡(a,m)=1\gcd(a,m) = 1 so m|b1−b2m|b_1-b_2 which means b1≡b2mod⁡mb_1\equiv b_2\mod m. However, −(m−1)≤b1−b2≤m−1-(m-1)\leq b_1-b_2\leq m-1 which implies b1=b2b_1 = b_2. ◻

Example 2.16. Let m=12m = 12 and a=5a = 5 so that gcd⁡(a,m)=1\gcd(a,m) = 1. Consider the set 0⋅5,1cot⁡5,…,12⋅50\cdot 5, 1\cot 5, \dots, 12\cdot 5 which is 0,5,10,3,8,1,6,11,4,9,2,70,5,10, 3,8,1,6,11,4,9,2,7 and we find that 5−1=55^{-1} = 5.

Theorem 2.17 (Fermat’s little theorem). Let pp be prime and a∈ℤa\in {\mathbb {Z}} such that pp does not divide aa. Then ap−1≡1mod⁡pa^{p-1}\equiv 1 \mod p. Also ap≡amod⁡pa^p \equiv a\mod p even if pp does divide aa.

Proof. Consider the set 1⋅a,2⋅a,…,(p−1)⋅a1\cdot a, 2\cdot a, \dots, (p-1)\cdot a which are all distinct modulo pp. Also, none are congruent to zero. This is because p|b⋅ap|b\cdot a implies p|bp|b since pp does not divide aa and 1≤b≤p−11\leq b \leq p-1 which implies pp does not divide bb so pp can’t divide baba. So ap−1(1⋅2⋅3⋯(p−1))≡1⋅2⋅3⋯(p−1))mod⁡pa^{p-1}(1\cdot 2\cdot 3\cdots (p-1)) \equiv 1\cdot 2\cdot 3\cdots (p-1)) \mod p. This implies that p|(ap−1)(1⋅2⋅3⋯(p−1))p|(a^{p-1})(1\cdot 2\cdot 3\cdots (p-1)), but gcd⁡(p,1⋅2⋅3⋯(p−1)))=1\gcd (p, 1\cdot 2\cdot 3\cdots (p-1)) ) =1 so p|ap−1−1p|a^{p-1}-1 as required. ◻

2.8 Euler’s generalization of FLT

Let φ(m){\varphi}(m) denote the number of integers 0≤c≤m0\leq c\leq m such that gcd⁡(c,m)=1\gcd(c,m) = 1.

Example 2.18. φ(12)=4{\varphi}(12) = 4 and φ(15)=8{\varphi}(15) = 8 having coprime c′sc's {1,5,7,11}\{1,5,7,11\} for 12 and {1,2,4,7,8,11,13,14}\{1,2,4,7,8,11,13,14\} for 15.

An integer c=qm+rc = qm + r with 0≤r<m0\leq r<m has gcd⁡(c,m)=1\gcd(c,m)=1 if and only if gcd⁡(r,m)=1\gcd(r,m) = 1. This says that the remainder specifies whether a number has a common factor with mm or not. Let c1,c2,…,cφ(m)c_1, c_2, \dots, c_{{\varphi}(m)} be distinct integers satisfying that 0≤ci<m0\leq c_i<m with gcd⁡(ci,m)=1\gcd(c_i, m) = 1. Let gcd⁡(a,m)=1\gcd(a, m) = 1 and consider the collection ac1,ac2,…,acφ(m)ac_1,ac_2,\dots, ac_{\varphi}(m). These are all distinct modulo mm and furthermore gcd⁡(aci,m)=1\gcd(ac_i, m) = 1 so the product ∏aci≡∏cimod⁡m\prod ac_i \equiv \prod c_i\mod m which means (again) that m|(aφ(m)−1)∏cim|(a^{{\varphi}(m)}-1)\prod c_i, but the gcd⁡(∏ci,m)=1\gcd(\prod c_i, m) = 1 so in fact m|aφ(m)−1m|a^{{\varphi}(m)}-1. Hence, aφ(m)≡1mod⁡ma^{{\varphi}(m)}\equiv 1\mod m.

Theorem 2.19 (Euler’s generalization of FLT). Let a,m∈ℤa,m\in {\mathbb {Z}} with m≥1m\geq 1 and gcd⁡(a,m)=1\gcd(a,m) = 1. Then aφ(m)≡1mod⁡ma^{{\varphi}(m)}\equiv 1\mod m where φ(m)={0≤c<m:gcd⁡(c,m)=1}{\varphi}(m) = \{0\leq c<m:\gcd(c,m) = 1\}.

Example 2.20. If m=15m = 15 and a=4a = 4 then (1⋅4)(2⋅4)(4⋅4)(7⋅4)(8⋅4)(11⋅4)(13⋅4)(14⋅4)≡1⋅2⋅4⋅7⋅8⋅11⋅13⋅14mod⁡1548≡1mod⁡15\begin{align*} (1\cdot 4)(2\cdot 4)(4\cdot 4)(7\cdot 4) (8\cdot 4)(11\cdot 4)(13\cdot 4)(14\cdot 4)&\equiv 1\cdot2\cdot4\cdot7\cdot8\cdot11\cdot13\cdot14\mod 15\\ 4^8\equiv 1\mod 15 \end{align*}

Some formulas for the Euler-phi function are given as follows

Proposition 2.21.

  1. If pp is prime, then φ(p)=p−1{\varphi}(p) = p-1.

  2. If pp is prime and α∈ℕ{\alpha}\in{\mathbb {N}} then φ(pα)=pα−pα−1=pα(1−1/p){\varphi}(p^{\alpha}) = p^{\alpha}- p^{{\alpha}-1} = p^{{\alpha}}(1-1/p).

  3. Let p,qp,q be distinct primes, then φ(pq)=pq−p−q+1{\varphi}(pq) = pq - p - q + 1.

  4. Let a,ba,b be coprime integers, then φ(ab)=φ(a)φ(b){\varphi}(ab) = {\varphi}(a){\varphi}(b).

proof (of 4.). First by illustration when a=6,b=5a = 6, b=5 write all of the numbers from 0 to ab−1=29ab-1= 29 in a block as 06121824171319252814202639152127410162228511172329\begin{matrix}0 & 6 & 12 & 18 & 24\\1& 7 & 13 & 19 & 25\\ 2& 8 & 14& 20 & 26\\3 & 9 & 15& 21& 27\\ 4 & 10 & 16 & 22& 28\\ 5 & 11& 17 & 23& 29\end{matrix} and notice that 6 divides the first row, 2 divides the third, 3 divides the fourth and 2 divides the fifth. So only the second and sixth rows are any good. This means, if 0≤m≤290 \leq m \leq 29 then 20 are immediately pulled out as having gcd⁡(m,30)=1\gcd(m, 30 ) = 1. Looking at the remaining two rows modulo b=5b = 5. Row 2 becomes 1,2,3,4,01,2,3,4,0 and of these five φ(5)=4{\varphi}(5)= 4 work. The sixth row becomes 0,1,2,3,40,1,2,3,4 and again φ(5)=4{\varphi}(5) = 4 work. We now have 2=φ(a)2 = {\varphi}(a) rows each providing 4=φ(5)4 = {\varphi}(5) valid m′sm's.

To generalize the above illustration, write 0a2a⋯(b−1)a1a+1⋯⋮2⋮a−12a−1⋯(b−1)a+a−1⏟=ab−1\begin{matrix}0 & a & 2a& \cdots & (b-1)a\\ 1& a+1 & \cdots & & \vdots\\ 2&&&&\\ \vdots &&&&\\a-1 &2a-1& \cdots & & \underbrace{(b-1)a+ a-1}_{=ab-1}\end{matrix} Recall that if m=qa+rm = qa + r with 0≤r<m0\leq r<m then gcd⁡(a,m)=gcd⁡(a,r)\gcd(a,m) = \gcd(a,r). Our goal is to pick out the mm’s in 0≤m<ab0\leq m <ab such that gcd⁡(m,ab)=1\gcd(m,ab) = 1 which holds if and only if both gcd⁡(m,a)=1\gcd(m,a) = 1 and gcd⁡(m,b)=1\gcd(m,b) = 1. This says, that we may restrict ourselves to φ(a){\varphi}(a) rows beginning with rr such that gcd⁡(r,a)=1\gcd(r,a) = 1. Next take a given row r,a+r,2a+r,…,(b−1)a+rr, a+r, 2a+r, \dots, (b-1)a+r. Modulo bb, this row forms a complete set of residues. So of these, exactly φ(b){\varphi}(b) are coprime with bb. All together this is φ(ab)=φ(a)⏟valid rows⋅φ(b)⏟valid number per row.{\varphi}(ab) = \underbrace{{\varphi}(a)}_{\text{valid rows}}\cdot \underbrace{{\varphi}(b)}_{\text{valid number per row}}. ◻

Making use of all of the above properties, then with n=p1α1⋯pkαkn = p_1^{{\alpha}_1}\cdots p_k^{{\alpha}_k} φ(n)=∏i=1kφ(piαi)=∏i=1kpiαi(1−1/pi)=n⋅∏p|n(1−1/p).{\varphi}(n) = \prod_{i=1}^k {\varphi}(p_i^{{\alpha}_i}) = \prod_{i=1}^k p_i^{{\alpha}_i}(1-1/p_i) = n\cdot \prod_{p|n}(1-1/p).

Proposition 2.22. ∑d|nφ(d)=n\sum_{d|n}{\varphi}(d) = n

Proof. Making use of Equation (1), ∑d|nφ(d)=∏i=1k(1+φ(pi)+φ(pi)2+⋯+φ(pi)αi)=∏i=1k(1+(pi−1)+pi(pi−1)+⋯+piαi−1(pi−1))=∏i=1k(1+(pi−1)⋅piαi−1pi−1)=∏i=1kpiαi=n.\begin{align*} \sum_{d|n}{\varphi}(d) &= \prod_{i=1}^k (1 + {\varphi}(p_i) + {\varphi}(p_i)^2+ \cdots+ {\varphi}(p_i)^{{\alpha}_i}) \\ &= \prod_{i=1}^k(1+ (p_i-1) + p_i(p_i-1) + \cdots + p_i^{{\alpha}_i-1}(p_i - 1))\\ &= \prod_{i=1}^k\left(1 + (p_i-1)\cdot\frac{p_i^{{\alpha}_i} - 1}{p_i-1}\right) = \prod_{i=1}^k p_i^{{\alpha}_i} = n. \end{align*} ◻

2.9 Chinese remainder theorem

Theorem 2.23 (Chinese remainder theorem). Let a,b∈ℤa,b\in {\mathbb {Z}} both ≥1\geq 1 and gcd⁡(a,b)=1\gcd(a,b) = 1. Given α,β∈ℤ{\alpha}, {\beta}\in {\mathbb {Z}} we can find an integer xx such that x≡αmod⁡ax\equiv {\alpha}\mod a and x≡βmod⁡bx\equiv{\beta}\mod b. Furthermore, the solution is unique if we restrict xx to be 0≤x≤ab0\leq x\leq ab. In other words, two simultaneous congruences x≡αmod⁡ax\equiv {\alpha}\mod a and x≡βmod⁡bx\equiv {\beta}\mod b are equivalent to a single congruence modulo abab.

This theorem allows us to simplify the above prove that gcd⁡(a,b)=1\gcd(a,b)=1 implies φ(ab)=φ(a)φ(b){\varphi}(ab) = {\varphi}(a){\varphi}(b). Indeed, Let m≡r1mod⁡am \equiv r_1\mod a and m≡r2mod⁡bm\equiv r_2\mod b with 0≤r1<a0\leq r_1< a and 0≤r2<b0\leq r_2< b. Now gcd⁡(m,ab)=1\gcd(m, ab) = 1 if and only if both gcd⁡(m,a)=gcd⁡(m,r1)=1\gcd(m, a) = \gcd(m, r_1) = 1 and gcd⁡(m,b)=gcd⁡(r2,b)=1\gcd(m, b) = \gcd(r_2, b)= 1 of which there are φ(a){\varphi}(a) and φ(b){\varphi}(b) possibilities respectively. By the Chinese Remainder Theorem (CRT), each pair (r1,r2)(r_1,r_2) provides a unique 0≤m≤ab0\leq m \leq ab satisfying the conditions m≡r1mod⁡am\equiv r_1\mod a and m≡r2mod⁡bm\equiv r_2\mod b. Thus there are all together φ(a)φ(b){\varphi}(a){\varphi}(b) pairs so demonstrating our claimed result.

Theorem 2.24 (Wilson’s Theorem). Let pp be prime, then (p−1)!≡−1mod⁡p(p-1)!\equiv -1\mod p.

Proof. Matching up inverse pairs 1,2,3,4,…,(p−1)1, 2, 3, 4, \dots, (p-1) are all invertible modulo pp since non share common factors with pp. Most of them are not equal to their own inverse2. Hence then, by matching inverse pairs, (p−1)!≡1⋅(p−1)≡(p−1)mod⁡p.(p-1)! \equiv 1\cdot (p-1) \equiv (p-1)\mod p. ◻

3 Polynomial Congruences

Theorem 3.1 (Lagrange’s Theorem). Let pp be prime, n∈ℤn\in {\mathbb {Z}} non negative and ai∈ℤa_i\in {\mathbb {Z}} with an≢0mod⁡pa_n\not\equiv 0\mod p. Then the polynomial equation anxn+an−1xn−1+⋯+a1x+a0≡0mod⁡pa_nx^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0 \equiv 0 \mod p has at most nn solutions modulo pp.

Proof. By induction on nn; This holds for n=0n=0 since a0≡0a_0\equiv 0 has no solutions. Furthermore, this is true when n=1n=1 since a1x+a0≡0mod⁡pa_1x+ a_0 \equiv 0 \mod p has one solution x≡a1−1a0mod⁡px \equiv a_1^{-1}a_0\mod p.

For the inductive step, the slick way is to use long division to pull out a linear factor for each root. Either anxn+an−1xn−1+⋯+a1x+a0≡0mod⁡pa_nx^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0 \equiv 0 \mod p has a root or not. If not, then zero roots is less than nn as claimed. If there is a root, say x1x_1, then the difference between our original equation from the and the same one with x1x_1 substituted for xx is an(xn−x1n)+⋯+a1(x−x1)=0a_n(x^n - x_1^n) + \cdots + a_1(x-x_1) = 0 which factors as (x−x1)⋅g(x)≡0mod⁡p(x-x_1)\cdot g(x) \equiv 0 \mod p where gg has integer coefficients and deg⁡g=n−1\deg g = n-1. Now, p|(x−x1)⋅g(x)p|(x-x_1) \cdot g(x) which implies p|(x1)p|(x_1) or g(x)g(x) (since pp is prime). Hence, by induction hypothesis there are at most one plus n−1n-1 solutions modulo pp. ◻

Example 3.2.

  1. x3−x≡0mod⁡3x^3 - x\equiv 0\mod 3 has 3 solutions x≡0,1,2mod⁡3x\equiv 0, 1, 2\mod 3.

  2. x3+1≡0mod⁡3x^3 + 1\equiv 0\mod 3 has 1 solution modulo 3 and that is x≡2mod⁡3x\equiv 2\mod 3.

  3. A counter example in the case that pp is not prime; x2−1≡0mod⁡8x^2 - 1\equiv 0 \mod 8 has 4(>2)(>2) solutions. These are x≡1,3,5,7mod⁡8x \equiv 1, 3, 5, 7\mod 8.

3.1 Primitive roots and Quadratic residues

Let m∈ℤm\in {\mathbb {Z}} be positive and a∈ℤa\in {\mathbb {Z}} such that gcd⁡(a,m)=1\gcd(a,m) = 1. The order of aa modulo mm is the smallest possible integer ll such that al≡1mod⁡ma^l\equiv 1\mod m.

Theorem 3.3 (Euler’s Theorem). If gcd⁡(a,m)=1\gcd(a,m) = 1 then aφ(m)≡1mod⁡ma^{{\varphi}(m) }\equiv 1\mod m which implies that the order of aa is ≤φ(m)\leq {\varphi}(m).

Example 3.4. m=11m = 11 and φ(m)=10{\varphi}(m)= 10.

3 Observe that

11≡1mod⁡111^1\equiv 1\mod 11
210≡1mod⁡112^{10}\equiv 1\mod 11
35≡1mod⁡113^{5}\equiv 1\mod 11
45≡1mod⁡114^{5}\equiv 1\mod 11
55≡1mod⁡115^{5}\equiv 1\mod 11

610≡1mod⁡116^{10}\equiv 1\mod 11
710≡1mod⁡117^{10}\equiv 1\mod 11
810≡1mod⁡118^{10}\equiv 1\mod 11
95≡1mod⁡119^{5}\equiv 1\mod 11
102≡1mod⁡1110^{2}\equiv 1\mod 11

and these exponents are all divisors of φ(m)=10{\varphi}(m) = 10.

Proof. Let gcd⁡(a,m)=1\gcd(a,m) = 1 and suppose ll is the order of aa. We have al≡1mod⁡ma^l \equiv 1\mod m, but ai≢1mod⁡ma^i\not\equiv 1\mod m for all 0<i<l0<i <l. We wish to show that l|φ(m)l|{\varphi}(m). Let φ(m)=ql+r{\varphi}(m) = ql+r with 0≤r<l0\leq r<l and show that r=0r = 0. By Euler’s Theorem, aφ(m)≡1mod⁡ma^{{\varphi}(m)} \equiv 1\mod m meaning that ar≡1⋅ar≡(al)q⋅ar≡aql+r≡aφ(m)≡1a^r \equiv 1\cdot a^r \equiv (a^l)^q \cdot a^r \equiv a^{ql+r} \equiv a^{{\varphi}(m)} \equiv 1. Thus, as already noted, we must have r=0r= 0 so that l|φ(m)l|{\varphi}(m) as required. ◻

Furthermore, if aa is known to have order ll modulo mm (and gcd⁡(a,m)=1\gcd(a, m)=1) then ak≡1mod⁡ma^k \equiv 1 \mod m if and only if ll divides kk. This holds for the same reason as the previous result.

Lemma 3.5. Let jj be a positive integer. If aa has order ll, then aja^j has order l/gcd⁡(l,j)l/\gcd(l,j).

Proof. Order of aja^j is the smallest integer kk such that ajk=(aj)k≡1mod⁡ma^{jk} = (a^j)^k \equiv 1 \mod m, hence if and only if l|jkl|jk. Let d=gcd⁡(j,l)d = \gcd(j,l) so that j=dj0j = dj_0 and l=dl0l = dl_0 with gcd⁡(j0,l0)=1\gcd(j_0, l_0) = 1. Now l|jkl|jk implies dl0|dj0kdl_0|dj_0k or, equivalently, l0|j0kl_0|j_0k meaning j0k=αl0j_0k = {\alpha}l_0 and so k=αl0j0k = \frac{{\alpha}l_0}{j_0}. But kk is an integer so we must have that j0|αl0j_0|{\alpha}l_0 which means j0|αj_0|{\alpha}. Thus, the smallest positive kk has α=j0{\alpha}= j_0 which implies k=l0=l/dk = l_0 = l/d as claimed. ◻

An integer a∈ℤa\in {\mathbb {Z}} is said to be a primitive root modulo mmif its order equals φ(m){\varphi}(m). Not all moduli have primitive roots (e.g. m=8m = 8 since 12=32=52=72≡1mod⁡81^2 = 3^2 = 5^2= 7^2\equiv 1 \mod 8 and φ(8)=4{\varphi}(8) = 4).

We claim that mm has a primitive root if and only if m=2,4,pαm = 2, 4, p^{\alpha} or 2pα2p^{\alpha} where pp is any odd prime and α≥1{\alpha}\geq 1. We shall demonstrate only that primes have primitive roots. For example, when p=11p = 11, the primitive roots are 2, 6, 7 and 8.

We have see that if aa has order ll modulo pp, then l|φ(p)=p−1l|{\varphi}(p) = p-1. Let fp(l)=#{1≤a≤p−1:al≡1mod⁡p}f_p(l) = \#\{1\leq a\leq p-1:a^l\equiv 1\mod p\} and notice that ∑l|p−1fp(l)=p−1\sum_{l|p-1}f_p(l) = p-1 which counts the number of aa’s according to their order.

We claim that

1. If l|p−1l|p-1 then f(l)≤φ(l)f(l) \leq {\varphi}(l), and

2. claim 1 implies f(l)=φ(l)f(l) = {\varphi}(l).

To show the second, assume that f(l)≤φ(l)f(l)\leq {\varphi}(l) so that p−1=∑l|p−1fp(l)≤∑l|p−1φ(l)=p−1.p-1 = \sum_{l|p-1}f_p(l) \leq \sum_{l|p-1}{\varphi}(l) = p-1.

Now, for the first claim, either f(l)=0f(l) = 0 or not, if f(l)=0f(l) = 0 then f(l)≤φ(l)f(l)\leq {\varphi}(l). If f(l)≠0f(l) \neq 0 then there is at least one aa with 1≤a≤p−11\leq a\leq p-1 with order ll and aj≢1mod⁡pa^j\not\equiv 1\mod p for all j∈{1,2,…,l−1}j\in \{1, 2, \dots, l-1\}. Now consider the equation xl−1≡0mod⁡px^l-1\equiv 0\mod p. aa is a solution to this equation and so are a2,a3,…,ala^2, a^3, \dots, a^l since (aj)l−1=(al)j−1≡0mod⁡p(a^j)^l - 1 = (a^l)^j - 1\equiv 0\mod p. Since aa has order ll, all of these aja^j’s are distinct modulo pp so we have found all solutions to this degree ll equation (Lagrange’s Theorem). Our goal then is to determine f(l)f(l) (i.e. how many elements have order ll).

Check how many of a,a2,a3,…,ala, a^2, a^3, \dots, a^l have order ll. If aa has order ll, then aja^j has order l/gcd⁡(j,l)l/\gcd(j,l) implying that φ(l){\varphi}(l) of the jj’s satisfy gcd⁡(j,l)=1\gcd(j,l) =1. Thus, if f(l)≠0f(l) \neq 0 then f(l)=φ(l)f(l) = {\varphi}(l). In particular, the number of primitive roots modulo pp is precisely φ(p−1){\varphi}(p-1).

Let gg be a primitive root modulo pp; then g,g2,g3,…,gp−1g, g^2, g^3, \dots, g^{p-1} are congruent to 1,2,3,…,p−11, 2, 3, \dots, p-1 mod pp only they re in some strange order.

Note that the primitive roots modulo 11 are 2,6,7,8 and there are φ(10)=φ(2)⋅φ(5)=(2−1)(5−1)=4{\varphi}(10) = {\varphi}(2)\cdot {\varphi}(5) = (2-1)(5-1) = 4 of them. So 2,22,23,…,29,2102, 2^2, 2^3, \dots, 2^9, 2^10 equal to 2,4,8,5,10,9,7,3,6,12,4,8,5,10,9,7,3,6,1 respectively.

3.2 kthk^{th} power residues

An integer aa is said to be a kthk^{th} power residue modulo pp if there exists some integer x∈ℤx\in {\mathbb {Z}} such that xk≡amod⁡px^k \equiv a \mod p. Otherwise, aa is a kthk^{th} power non-residue mod pp. Note that we do not consider a≡0mod⁡pa\equiv 0\mod p.

Example 3.6. The quadratic residues modulo 11 are found from the following table;

121^2 222^2 323^2 424^2 525^2 626^2 727^2 828^2 929^2 10210^2
1 4 9 5 3 3 5 9 4 1

Hence 1,3,4,5,91,3,4,5,9 are quadratic residues.

In terms of our primitive root, g=2g = 2, all quadratic residues are of the form g2mg^{2m} with m=1,2,3,4,5m= 1,2,3,4,5.

Let gg be a primitive root modulo pp and rewrite xk≡amod⁡px^k\equiv a\mod p in terms of gg as follows; a=gαa = g^{\alpha} and x=gλx = g^{\lambda} for some α,λ∈{1,2,…,p−1}{\alpha},{\lambda}\in \{1,2,\dots, p-1\}. The congruence then becomes (gλ)k≡g|almod⁡p(g^{\lambda})^k\equiv g^|al\mod p which is equivalent to λk=αmod⁡p−1{\lambda}k = {\alpha}\mod p-1 which can be solved if and only if gcd⁡(k,p−1)\gcd(k, p-1) divides α{\alpha}.

Note that ax≡bmod⁡max\equiv b\mod m has solutions if and only if gcd⁡(a,m)|b\gcd(a,m)|b. Indeed, let d=gcd⁡(a,m)d = \gcd(a,m) and if d|bd|b then the original equation is equivalent to (a/d)x≡b/dmod⁡m/d(a/d)x\equiv b/d \mod m/d. A solution to this equation (modulo m/dm/d) gives rise to dd solutions modulo mm of the original equation. We have then solutions above if and only if gcd⁡(k,p−1)|α\gcd(k,p-1) | {\alpha}. If so, then there are dd solutions modulo p−1p-1 to our equation. x2≡amod⁡11x^2\equiv a \mod 11 if and only if λ⋅2≡αmod⁡11−1=10{\lambda}\cdot 2 \equiv {\alpha}\mod 11-1 = 10. gcd⁡(2,10=2\gcd(2,10 = 2 which implies 2|α2|{\alpha} for 1≤α≤101\leq {\alpha}\leq 10 so 10/2=510/2 = 5 of the α{\alpha}’s are quadratic residues.

Let pp be a prime and gg a primitive root modulo pp. You can write any 1≤a≤p−11\leq a\leq p-1 as a≡gαmod⁡pa \equiv g^{\alpha}\mod p> for some 1≤α≤p−11\leq {\alpha}\leq p-1. This α{\alpha} is called the index of aa relative to the primitive root gg (mod pp). α{\alpha} is uniquely specified if we restrict it to 1≤α≤p−11\leq {\alpha}\leq p-1 as powers of gg (mod pp) repeat every p−1p-1 (since gg has order p−1p-1). Now, gα′≡gαmod⁡pg^{{\alpha}'} \equiv g^{\alpha}\mod p which is equivalent to α′=m(p−1)+α{\alpha}' = m(p-1) + {\alpha} which implies α′≡αmod⁡p−1{\alpha}'\equiv {\alpha}\mod p-1. Indeed, α′=m(p−1)+α{\alpha}' = m(p-1) + {\alpha} implies gα′≡gm(p−1)+α≡(gp−1)m⋅gα≡gαmod⁡pg^{{\alpha}'} \equiv g^{m(p-1)+ {\alpha}} \equiv (g^{p-1})^m \cdot g^{\alpha}\equiv g^{\alpha}\mod p. Conversely, if α′=m(p−1)+r{\alpha}' = m(p-1) + r with 1≤r≤p−11\leq r\leq p-1 (where r=0r = 0 is not important. then gα′=gm(p−1)+r≡(gp−1)m⋅gr≡grmod⁡pg^{{\alpha}'} = g^{m(p-1) + r} \equiv (g^{p-1})^m \cdot g^r \equiv g^r\mod p. If gα′≡gαmod⁡pg^{{\alpha}'} \equiv g^{{\alpha}} \mod phtne gr≡gαg^r \equiv g^{\alpha} so that r=αr = {\alpha} because the powers of gg do not repeat with the constraint 1≤r,α≤p−11\leq r,{\alpha}\leq p-1.

Example 3.7. g=3g= 3 is a primitive root mod 7.

3 323^2 333^3 343^4 353^5 363^6
3 2 6 4 5 1

The primitive roots mod 11 are 2,6,7,82,6,7,8 powers of 2 are

2 222^2 232^3 242^4 252^5 262^6 272^7 282^8 292^9 2102^{10} 2112^{11} 2122^{12}
2 4 8 5 10 9 7 3 6 1 2 4

The aa’s which are quadratic residues modulo 11 are 1,3,4,5,9. If you didn’t know about primitive roots then you could square all of the integers mod 11.

If x2≡amod⁡px^2 \equiv a\mod p then (p−x)2≡(−x)2≡x2≡amod⁡p(p-x)^2 \equiv (-x)^2 \equiv x^2 \equiv a\mod p. So quadratic residues, if any always occur in pairs xx and p−xp-x.

Example 3.8. Cubic residue modulo 11. x3≡amod⁡11x^3 \equiv a\mod 11 in terms of primitive root gg. Let x=gλx = g^{\lambda} and a≡gαa \equiv g^{\alpha} then g3λ≡gαmod⁡pg^{3{\lambda}} \equiv g^{\alpha}\mod p means that 3λ≡αmod⁡p−13{\lambda}\equiv {\alpha}\mod p-1. Here p=11p = 11 so we want 3λ≡αmod⁡103{\lambda}\equiv {\alpha}\mod 10. gcd⁡(3,10)=1\gcd(3,10 ) = 1 and 1|α1|{\alpha} for all α=1,2,…,10{\alpha}= 1,2, \dots, 10. Hence all such α{\alpha} are cubic residues mod 11.

Check;

xx 1 2 3 4 5 6 7 8 9 10
x3x^3 1 8 5 9 4 7 2 6 3 10

Lets now take a look at 5th5^{th} power residues mod 11. Again, we seek to solve 5λ≡αmod⁡105{\lambda}\equiv {\alpha}\mod 10. gcd⁡(5,10)=5\gcd(5,10 ) = 5 so we must have 5|α5|{\alpha} meaning that α=5{\alpha}= 5 or 10. Examining powers of g=2g= 2, which are

2 222^2 232^3 242^4 252^5 262^6 272^7 282^8 292^9 2102^{10}
2 4 8 5 10 9 7 3 6 1

and our theory suggests that only x5≡10mod⁡11x^5\equiv 10 \mod 11 and x5≡1mod⁡11x^5\equiv 1\mod 11 can be solved while all other x5≡amod⁡11x^5\equiv a\mod 11 can not be solved.

Checking this,

xx 1 2 3 4 5 6 7 8 9 10
x5x^5 1 10 1 1 1 10 10 10 1 10

3.3 Quadratic residues

Let pp be an odd prime. How many of 1≤a≤p−11\leq a\leq p-1 are quadratic residues? We have seen that gcd⁡(2,p−1)=2\gcd(2, p-1) = 2 which implies there are p−12\frac{p-1}{2} quadratic residues. We also saw that these quadratic residues come in pairs. x,p−xx, p-x.

For p=11p = 11, all quadratic residues appear once as an x2x^2 with 1≤x≤p−121\leq x\leq \frac{p-1}{2}.

Proposition 3.9.

  1. The product of 2 quadratic residues mod pp is a quadratic residue,

  2. The product of two quadratic non-residues mod⁡p\mod p is a quadratic residue, and

  3. The product of a quadratic non-residue with a quadratic residue is a quadratic non-residue mod⁡p\mod p.

Proof. Write everything in terms of a primitive root, Let a=gα,b=gβa = g^{\alpha}, b = g^{\beta} so that a⋅b=gα+βa\cdot b = g^{{\alpha}+ {\beta}} and this result becomes equivalent to parity of the sum of two integers. ◻

Definition 3.10 (Legendre Symbol). Let pp be prime and a∈ℤa\in {\mathbb {Z}}. Define the Legendre Symbol as (ap)=(a|p)={+1, if a is a quadratic residuemod⁡p−1, if a is a quadratic non-residuemod⁡p0, if a≡0mod⁡p\left(\frac{a}{p}\right) = (a|p) = \begin{cases} +1, \text{ if } a \text{ is a quadratic residue} \mod p\\ -1, \text{ if } a \text{ is a quadratic non-residue} \mod p \\ 0, \text{ if } a\equiv 0\mod p\end{cases}

Example 3.11. Let p=5p = 5, then

aa 0 1 2 3 4
(a5)\left(\frac{a}{5}\right) 0 1 -1 -1 1

If we write a=gαa = g^{\alpha} where gg is a primitive root mod pp, then aa is a quadratic residue if and only if α{\alpha} is even. So (for a≢0mod⁡pa\not\equiv 0\mod p) we have (ap)=(−1)α.\left(\frac{a}{p}\right) = (-1)^{\alpha}.

The above proposition then boils down to say, when a≡gα,b≡gβa \equiv g^{\alpha}, b\equiv g^{\beta}, (a⋅bp)=(−1)α+β=(−1)α⋅(−1)β=(ap)⋅(bp)\left(\frac{a\cdot b}{p}\right) = (-1)^{{\alpha}+{\beta}} = (-1)^{\alpha}\cdot (-1)^{\beta}= \left(\frac{a}{p}\right)\cdot \left(\frac{b}{p}\right) and this identity extends even when one of aa or bb is 0 mod pp.

Question: When is -1 a quadratic residue modulo pp? That is to ask, for which pp does x2≡−1mod⁡px^2 \equiv -1\mod p have solutions?

Answer: Assuming pp is odd then there are solutions if an only if p=4k+1p = 4k+1 for some k∈ℤk\in {\mathbb {Z}}. This proof makes use of Euler’s criterion which we must first discuss.

Lemma 3.12 (Euler’s criterion). (ap)≡ap−12mod⁡p.\left(\frac{a}{p}\right) \equiv a^{\frac{p-1}{2}}\mod p.

Before this is proven, we remark that the beauty of this formula is that it does not require primitive roots, however it is practically limited.

Proof. First observe that p−1p-1 is even (since pp is odd). Now, if a≢0mod⁡pa\not\equiv 0\mod p then ap−1≡1mod⁡pa^{p-1}\equiv 1\mod p (Fermat’s Little Theorem). That is, (ap−12−1)(ap−12+1)≡0mod⁡p(a^{\tfrac{p-1}{2}}-1)(a^{\tfrac{p-1}{2}}+1) \equiv 0\mod p (this only hold because p-1 is even). Hence we must have that p|ap−12±1p|a^{\tfrac{p-1}{2}}\pm 1 so to say ap−12≡±1mod⁡pa^{\tfrac{p-1}{2}}\equiv \pm 1\mod p. Now, either aa is a quadratic residue, or it is not. If it is, then a=gαa = g^{\alpha} for some even α{\alpha}, say α=2α0{\alpha}= 2{\alpha}_0 so that ap−12≡gα0(p−1)≡1α0≡1mod⁡pa^{\tfrac{p-1}{2}} \equiv g^{{\alpha}_0(p-1)}\equiv 1^{{\alpha}_0} \equiv 1\mod p. Hence, in this case (ap)=1≡ap−12mod⁡p\left(\frac{a}{p}\right) = 1\equiv a^{\tfrac{p-1}{2}}\mod p.

Otherwise, then a=gαa = g^{{\alpha}} with α{\alpha} odd, say α=2α0+1{\alpha}= 2{\alpha}_0+1. So, ap−12≡gα0(p−1)⋅gp−12≡gp−12=±1mod⁡pa^{\tfrac{p-1}{2}}\equiv g^{{\alpha}_0(p-1)}\cdot g^{\tfrac{p-1}{2}} \equiv g^{\tfrac{p-1}{2}} = \pm 1\mod p (from above). However gp−12≢1mod⁡pg^{\tfrac{p-1}{2}} \not\equiv 1\mod p since gg has order p−1p-1. Therefore, gp−12≡−1mod⁡pg^{\tfrac{p-1}{2}} \equiv -1\mod p. ◻

Note that if a≡a′mod⁡pa\equiv a'\mod p then (ap)=(a′p)\left(\frac{a}{p}\right) = \left(\frac{a'}{p}\right).

Question: Suppose aa is fixed and we vary pp. How does the Legendre symbol depend on pp?

Partial answer: (ap)\left(\frac{a}{p}\right) is determined according to pp (mod⁡|4a|\mod |4a|). We will see that (−1p)={1 iff p=4k+1−1 iff p=4k+3\left(\frac{-1}{p}\right) = \begin{cases}1\text{ iff } p = 4k+1\\ -1 \text{ iff } p=4k+3\end{cases} Also, (2p)={1, if p=8k+1 or 8k+7−1, if p=8k+3 or 8k+5\left(\frac{2}{p}\right) = \begin{cases}1, \text{ if } p = 8k+1\text{ or } 8k+7\\ -1, \text{ if } p = 8k+3\text{ or } 8k+5\end{cases} For example, (211)=−1\left(\frac{2}{11}\right) = -1 and 11=8(1)+311 = 8(1) + 3.

The first formula here is a simple extension of Euler’s formula; (−1p)=(−1)p−12\left(\frac{-1}{p}\right) = (-1)^{\frac{p-1}{2}}

A method to the madness of quadratic residues,

Lemma 3.13 (Gauss’ Lemma). Let a≢mod⁡pa \not \equiv\mod p. Consider a,2a,3a,…,(p−12)aa, 2a, 3a, \dots, \left(\frac{p-1}{2}\right)a with pp an odd prime. Reduce them all modulo pp so the lie in the interval (0,p)(0, p). Some will be big (i.e. >p/2>p/2) and some will be small (i.e. <p/2<p/2). For the big ones, subtract another multiple of pp, so that ia≡rimod⁡pia\equiv r_i\mod p with each −p/2<ri<p/2-p/2<r_i<p/2 for all ii.

For example, if p=11p = 11 and a=3a = 3 we consider 3,2⋅3,3⋅3,4⋅3,5⋅3=3,6,9,1,4=3,−5,−2,1,43, 2\cdot 3, 3\cdot 3, 4\cdot 3, 5\cdot 3 = 3,6,9,1,4 = 3,-5,-2,1,4.

Let ν\nu represent the number of negative rir_i’s resulting from this procedure (so in our example ν=2\nu = 2). Then, Gauss’ Lemma states that (ap)=(−1)ν.\left(\frac{a}{p}\right) = (-1)^\nu.

Observe that the rir_i’s are just the numbers 1,2,…,p−121, 2, \dots, \frac{p-1}{2}, but with each having a signature. So (1⋅3)(2⋅3)(3⋅3)(4⋅3)(5⋅3)≡(−1)2(1⋅2⋅3⋅4⋅5)mod⁡11(1\cdot 3)(2\cdot 3)(3\cdot 3)(4\cdot 3)(5\cdot 3) \equiv (-1)^2(1\cdot 2\cdot 3 \cdot 4 \cdot 5)\mod 11 which is equivalent to 35≡(−1)2mod⁡113^5 \equiv (-1)^2\mod 11 Now Euler’s formula is (ap)=ap−12mod⁡p\left(\frac{a}{p}\right) = a^{\frac{p-1}{2}}\mod p so, (311)=35≡(−1)2≡1mod⁡11.\left(\frac{3}{11}\right) = 3^5 \equiv (-1)^2 \equiv 1\mod 11.

Let i⋅a≡rimod⁡pi\cdot a\equiv r_i\mod p with −p/2<ri<p/2-p/2<r_i<p/2 for each i=1,…,p−12i = 1, \dots, \frac{p-1}{2}. We claim that |r1|,|r2|,…,|rp−12||r_1|, |r_2|, \dots, |r_{\frac{p-1}{2}}| are the numbers 1,2,3,…,p−121,2, 3, \dots, \frac{p-1}{2} in some weird order. If the claim is true then ∏i=1p−12i⋅a≡(−1)ν∏i=1p−12imod⁡p\prod_{i=1}^{\frac{p-1}{2}} i\cdot a \equiv (-1)^\nu \prod_{i=1}^{\frac{p-1}{2}}i\mod p Now, since gcd(ri,p)=1gcd(r_i, p) = 1 for each ii, we may cancel the rir_i’s on either side, so this is equivalent to ap−12≡(−1)νmod⁡p.a^{\frac{p-1}{2}} \equiv (-1)^\nu\mod p. That is (ap)=(−1)ν\left(\frac{a}{p}\right) = (-1)^\nu. So it remains to prove that ri≠±rjr_i\neq \pm r_j for 1≤i<j≤p−121\leq i<j\leq \frac{p-1}{2}. By construction we have −p/2<ri<p/2-p/2<r_i<p/2 which implies also that −p−12≤ri≤p−12-\frac{p-1}{2}\leq r_i\leq \frac{p-1}{2} and since ri≢0mod⁡pr_i\not\equiv 0 \mod p because a⋅i≢0mod⁡pa\cdot i\not \equiv 0\mod p.

We now have two cases;
1. a⋅i≡a⋅jmod⁡pa\cdot i \equiv a\cdot j\mod p means that p|a(i−j)p|a(i-j) so p|i−jp|i-j and hence i≡jmod⁡pi\equiv j\mod p and finally then i=ji=j.
2. ri≡−rjmod⁡pr_i\equiv - r_j\mod p implies p|i+jp|i+j, but 3≤i+j≤p−12+p−12<p3\leq i+j\leq \frac{p-1}{2} + \frac{p-1}{2} <p so i=ji =j.

3.4 Applications of Gauss’ Lemma

Suppose a=−1a = -1, then a,2a,…,p−12aa, 2a, \dots, \frac{p-1}{2}a is −1,−2,−3,…,(−1)p−12-1, -2, -3, \dots, (-1)\frac{p-1}{2}. Notice that they already fall in our interval (−p/2,p/2)(-p/2, p/2) so there is no need to further reduce. They are also all negative so ν=p−12\nu = \frac{p-1}{2}. Hence,

(−1p)=(−1)p−12={1,p=4k+1−1,p=4k+3\boxed{\left(\frac{-1}{p}\right) = (-1)^{\frac{p-1}{2}} = \begin{cases}1, p = 4k+1\\ -1, p = 4k+3\end{cases}}

As a second application, suppose a=2a = 2 and pp is an odd prime. Then 2,2⋅2,3⋅2,…,p−12⋅2=p−12, 2\cdot 2, 3\cdot 2, \dots, \frac{p-1}{2}\cdot 2 = p-1. All of these lie in the interval (0,p)(0,p) so roughly 1/2 of them are too big. Let us be more specific,

We must now count the even number 2x2x for which p/2<2x<pp/2<2x<p. That is how many integers xx satisfy p/4<x<p/2p/4<x<p/2? This depends on pp modulo 8. Suppose p=8k+rp = 8k+r where r=1,3,5r = 1, 3, 5 or 77. Now p/4<x<p/2⇔2k+r/4<x<4k+r/2p/4<x<p/2\Leftrightarrow 2k + r/4<x<4k+r/2. We are really only concerned with the parity of ν\nu which is equivalent to the number of integers xx satisfying r/4<x<r/2r/4<x<r/2;
When r=1r = 1 there are no integers in the interval (1/4,1/2)(1/4, 1/2) so ν\nu is even.
When r=3r = 3 there is one integer in the interval (3/4,3/2)(3/4, 3/2) so ν\nu is odd.
When r=5r = 5 there is one integer in the interval (5/4,5/2)(5/4, 5/2).
When r=7r = 7 there are two integers in (7/4,7/2)(7/4, 7/2).

Therefore, (2p)={1, if p=8k+1 or 8k+7−1, if p=8k+3 or 8k+5\boxed{\left(\frac{2}{p}\right) = \begin{cases}1, \text{ if } p = 8k+1\text{ or } 8k+7\\ -1, \text{ if } p = 8k+3\text{ or } 8k+5\end{cases}}

3.5 Quadratic reciprocity

Theorem 3.14 (Quadratic Reciprocity). Let p,qp,q be distinct odd primes, then (pq)⋅(qp)=(−1)p−12⋅q−12={−1, if both p≡q≡3mod⁡41, else\boxed{\left(\frac{p}{q}\right)\cdot \left(\frac{q}{p}\right) = (-1)^{\frac{p-1}{2}\cdot\frac{q-1}{2}} = \begin{cases}-1, \text{ if both } p\equiv q\equiv 3\mod 4\\ 1, \text{ else}\end{cases}}

Euler conjectured while Gauss proved at the age of nineteen that if aa is a positive integer and pp is an odd prime with a≢0mod⁡pa\not\equiv 0\mod p, then the value of (ap)\left(\frac{a}{p}\right) is determined by the value of pp modulo 4a4a. Namely, if p1≡p2mod⁡4ap_1\equiv p_2\mod 4a then (ap1)=(ap2)\left(\frac{a}{p_1}\right) = \left(\frac{a}{p_2}\right). Furthermore, by symmetry, if p1≡−p2mod⁡4ap_1\equiv - p_2\mod 4a then (ap1)=(ap2)\left(\frac{a}{p_1}\right) = \left(\frac{a}{p_2}\right).

Proof. Consider a,2a,3a,…,p−12aa, 2a, 3a, \dots, \frac{p-1}{2}a and reduce by subtracting multiples of pp so they all lie in the interval [−p−12,p−12]\left[-\frac{p-1}{2}, \frac{p-1}{2}\right]. Each of the i⋅ai\cdot a lie in some interval (0,p/2),(p/2,p),(p,3p/2),…,((b−1/2)p,bp)(0,p/2), (p/2, p), (p, 3p/2), \dots, ((b-1/2)p, bp) and we only need a finite number of these intervals because b=a/2b = a/2 when aa is even covers them all and b=a−12b= \frac{a-1}{2} does when aa is odd. We are not omitting any i⋅ai\cdot a by taking open intervals since none of them are multiples of pp or p/2p/2. Let i⋅a≡rimod⁡pi\cdot a\equiv r_i\mod p with each ri∈[−p−12,p−12]r_i\in \left[-\frac{p-1}{2}, \frac{p-1}{2}\right]. The negative rir_i’s come from multiples which lie in intervals of the form ((b−1/2)p,bp)((b-1/2)p, bp) and Gauss’ Lemma implies that (ap)=(−1)ν\left(\frac{a}{p}\right) = (-1)^\nu. So how many axax satisfy that ax∈((b−1/2)p,bp)ax\in ((b-1/2)p, bp) is equivalent to asking how many integers lie between (p/2a,p/a),(3p/2a,2p/a),…,((b−1/2)p/a,bp/a)(p/2a, p/a), (3p/2a, 2p/a), \dots, ((b-1/2)p/a, bp/a), but p≡rmod⁡4ap \equiv r\mod 4a implies p=4ak+rp = 4ak+r with 0≤r<4a0\leq r<4a and the intervals become (2k+r2a,4k+ra),(6k+3r2a,8k+2ra),…,((2b−1)2k+(2b−1)r2a,4bk+bra).\left(2k+\frac{r}{2a}, 4k+\frac{r}{a}\right), \left(6k+\frac{3r}{2a}, 8k+ \frac{2r}{a}\right), \dots, \left((2b-1)2k +\frac{(2b-1)r}{2a}, 4bk + \frac{br}{a}\right). Since we are only interested in the parity of the number of integers between, we may reduce the problem to the intervals (r2a,ra),(3r2a,3ra),…((2b−1)r2a,bra)\left(\frac{r}{2a}, \frac{r}{a}\right), \left(\frac{3r}{2a}, \frac{3r}{a}\right), \dots \left(\frac{(2b-1)r}{2a}, \frac{br}{a}\right). Now the only dependence of whether ν\nu is even or odd is on rr and aa. Hence (ap1)=(ap2)\left(\frac{a}{p_1}\right) = \left(\frac{a}{p_2}\right) if p1≡±p2mod⁡4ap_1\equiv \pm p_2\mod 4a. ◻

Now we are in position to prove Quadratic reciprocity;

Proof. If p,qp,q are distinct odd primes, then (pq)={(qp), if at least one of p,q are congruent to 1mod⁡4−(qp) if both p≡q≡3mod⁡4\left(\frac{p}{q}\right) = \begin{cases}\left(\frac{q}{p}\right), \text{ if at least one of }p,q\text{ are congruent to 1}\mod 4\\ -\left(\frac{q}{p}\right)\text{ if both } p\equiv q\equiv 3\mod 4\end{cases} Verifying this, if p≡qmod⁡4p\equiv q\mod 4 then 4|p−q4|p-q so p=4k+qp = 4k+q for some integer kk. Now, (pq)=(4k+qq)=(4q)(kq)=(kq)\left(\frac{p}{q}\right) = \left(\frac{4k+q}{q}\right) = \left(\frac{4}{q}\right)\left(\frac{k}{q}\right) = \left(\frac{k}{q}\right) and (qp)=(p−4kp)=(−1p)(kp)={−(kp),p≡3mod⁡4(kp),p≡1mod⁡4\left(\frac{q}{p}\right) = \left(\frac{p-4k}{p}\right) = \left(\frac{-1}{p}\right)\left(\frac{k}{p}\right) = \begin{cases}-\left(\frac{k}{p}\right), p\equiv 3\mod 4\\ \left(\frac{k}{p}\right), p\equiv 1\mod 4\end{cases} So Euler’s conjecture implies that (kp)=(kq)\left(\frac{k}{p}\right) = \left(\frac{k}{q}\right) when p≡qmod⁡4p\equiv q\mod 4 so our result holds when p≡qp\equiv q.

Now, if p≢qmod⁡4p\not\equiv q \mod 4 then p≡−qmod⁡4p \equiv -q\mod 4 (i.e. p≡1p\equiv 1 and q≡3mod⁡4q \equiv 3\mod 4 or vice versa). So p≡−qmod⁡4p\equiv -q\mod 4 meaning that 4|p+q4|p+q and so p=4k−qp = 4k -q. Thus, (pq)=(4k−qq)=(kq)=(kp)=⋯=(qp)\left(\frac{p}{q}\right) = \left(\frac{4k-q}{q}\right) = \left(\frac{k}{q}\right) = \left(\frac{k}{p}\right) = \cdots = \left(\frac{q}{p}\right) and we are done. ◻

With this, we can compute several Legendre symbols;

Example 3.15. (51101)=(3101)(17101)=(1013)(10117)=(23)(−117)=(−1)(1)=−1\left(\frac{51}{101}\right) = \left(\frac{3}{101}\right)\left(\frac{17}{101}\right) =\left(\frac{101}{3}\right)\left(\frac{101}{17}\right) = \left(\frac{2}{3}\right)\left(\frac{-1}{17}\right) = (-1)(1) = -1

4 Continued fractions

A real number α∈ℝ{\alpha}\in {\mathbb {R}} may be expresses as α=q0+α′{\alpha}= q_0 + {\alpha}' where q0∈ℤq_0\in {\mathbb {Z}} and α′∈(0,1){\alpha}'\in (0,1). Next write α′=1α1{\alpha}' = \frac{1}{{\alpha}_1} where α1>1{\alpha}_1>1. Repeating this process on α{\alpha} provides a way of writing α{\alpha} as a fraction (possibly continuing forever).

Example 4.1. π=3.1415926535...=3+.1415926…=3+17.06251…=3+17+115.9965…=3+17+115+1292+11+…\begin{align*} \pi = 3.1415926535... &= 3 + .1415926\dots \\ &= 3+ \frac{1}{7.06251\dots}\\ &= 3+ \frac{1}{7+ \frac{1}{15.9965\dots}}\\ &= 3+ \frac{1}{7+\frac{1}{15 + \frac{1}{292 + \frac{1}{1+ \dots}}}} \end{align*}

and 9337=2+1937=2+137/19=2+11+1819=2+11+11+118\frac{93}{37} = 2 + \frac{19}{37} = 2 + \frac{1}{37/19} = 2+ \frac{1}{1 + \frac{18}{19}} = 2 + \frac{1}{1 + \frac{1}{1+ \frac{1}{18}}}

Let A,B∈ℤA, B\in {\mathbb {Z}} with B>0B>0. Euclidean algorithm gives A=Bq0+r0,0≤r0<BA = Bq_0 + r_0, 0\leq r_0 <B, B=q1r0+r1,0≤r1<r0,…,rn−2=qnrn−1+0B= q_1r_0 + r_1, 0\leq r_1<r_0, \dots, r_{n-2} = q_nr_{n-1} + 0. So,

AB=q0+r0B=q0+1B/r0=q0+1q1+r1r0=…=q0+1q1+1q2+1…+1qn.\frac{A}{B} = q_0 + \frac{r_0}{B} = q_0 + \frac{1}{B/r_0} = q_0 + \frac{1}{q_1 + \frac{r_1}{r_0}}= \dots = q_0 + \frac{1}{q_1+ \frac{1}{q_2 + \frac{1}{\dots + \frac{1}{q_n}}}}. We have shown how to obtain the continued fraction when α{\alpha} is rational and recognized that the continued fraction for a rational number terminates after finitely many steps. Furthermore, the converse of this is true because continued fractions which terminate can be put over a common denominator.

4.1 Finite continued fractions

Consider a fraction of the form q0+1q1+1q2+1…+1qnq_0 + \frac{1}{q_1+ \frac{1}{q_2 + \frac{1}{\dots + \frac{1}{q_n}}}} Are there any patterns? q0+1q1=q0q1+1q1,q0+1q1+1q2=q0+1q1q2+1q2=q0q1q2+q0+q2q1q2+1,q0+1q1+1q2+1q3=q0+q2q3+1q1q2q3+q1+q3=q0q1q2q3+q0q1+q3+q2q3+1q1q2q3+q1+q3\begin{align*} q_0 + \frac{1}{q_1} &= \frac{q_0q_1+1}{q_1},\\ q_0 + \frac{1}{q_1+\frac{1}{q_2}} &= q_0 + \frac{1}{\frac{q_1q_2+1}{q_2} }= \frac{q_0q_1q_2+ q_0+q_2}{q_1q_2+1},\\ q_0 + \frac{1}{q_1+\frac{1}{q_2+ \frac{1}{q_3}}}&= q_0+ \frac{q_2q_3+1}{q_1q_2q_3+q_1+q_3} = \frac{q_0q_1q_2q_3 + q_0q_1+ q_3+q_2q_3+ 1}{q_1q_2q_3 + q_1+q_3} \end{align*} This gives a recursion for the numerator and denominator of a continued fraction. Let [q0,q1,q2,…,qn][q_0, q_1,q_2, \dots, q_n] denote the numerator of the fraction so the denominator will be given by [q1,q2,…,qn][q_1,q_2,\dots, q_n]. The recursion for the numerator is thus, [q0,q1,…,qn]=q0[q1,…,qn]+[q2,…,qn].[q_0, q_1, \dots, q_n] = q_0[q_1,\dots, q_n] + [q_2, \dots, q_n].

Note that continued fraction for α{\alpha} terminates if and only if α{\alpha} is rational.

Example 4.2. [q0,q1,q2,q3]=q0[q1,q2,q3]+[q2,q3]=q0(q1[q2,q3]+[q3])+q2q3+1=q0(q1(q2q3+1)+q3)+q2q3+1=q0q1q2q3+q0q1+q0q3+q2q3+1\begin{align*} [q_0,q_1,q_2,q_3] & = q_0[q_1,q_2,q_3] + [q_2, q_3]\\ &= q_0(q_1[q_2, q_3] + [q_3]) + q_2q_3 + 1\\ &= q_0(q_1(q_2q_3+1) + q_3) + q_2q_3+1\\ &= q_0q_1q_2q_3 + q_0q_1 + q_0q_3 + q_2q_3 + 1 \end{align*} so now we may write q0+1q1+1q2+1…+1qn=[q0,q1,q2,…,qn][q1,q2,…,qn]q_0 + \frac{1}{q_1+ \frac{1}{q_2 + \frac{1}{\dots + \frac{1}{q_n}}}} = \frac{[q_0, q_1,q_2, \dots, q_n]}{[q_1,q_2,\dots, q_n]}

Euler’s Rule for continued fractions is that [q0,q1,…,qn][q_0, q_1,\dots, q_n] is given as the sum of products of qq’s where pairs of adjacent qq’s are omitted.

Observe [q0,q1,q2,q3,q4]=q0q1q2q3q4+q2q3q4+q0q3q4+q0q1q4+q0q1q2⏟omit one adjacent pair+q0+q4+q2⏟omit two pairs of adjacents[q_0,q_1,q_2,q_3,q_4] = q_0q_1q_2q_3q_4 + \underbrace{q_2q_3q_4+ q_0q_3q_4 + q_0q_1q_4 + q_0q_1q_2}_{\text{omit one adjacent pair}} + \underbrace{q_0 + q_4+ q_2}_{\text{omit two pairs of adjacents}}

and [q0,q1,q2,q3]=q0q1q2q3+q0q1+q0q3+q2q3+1[q_0, q_1, q_2, q_3] = q_0q_1q_2q_3 + q_0q_1 + q_0q_3 + q_2q_3 + 1.

This is simply proven by induction since we have the recursive formula [q0,q1,…,qn]=q0[q1,…,qn]+[q2,…,qn][q_0, q_1, \dots, q_n] = q_0[q_1,\dots, q_n] + [q_2, \dots, q_n]

Corollary 4.3. [q0,q1,…,qn]=[qn,…,q1,q0][q_0, q_1, \dots, q_n] = [q_n, \dots, q_1, q_0] so that the fractions q0+1q1+1q2+1…+1qnq_0 + \frac{1}{q_1+ \frac{1}{q_2 + \frac{1}{\dots + \frac{1}{q_n}}}} and qn+1qn−1+1qn−2+1…+1q0q_n + \frac{1}{q_{n-1}+ \frac{1}{q_{n-2} + \frac{1}{\dots + \frac{1}{q_0}}}} have the same numerator.

For example, 3+14+15=3+521=68213 + \frac{1}{4 + \frac{1}{5}} = 3 + \frac{5}{21} = \frac{68}{21} and 5+14+13=5+313=68135 + \frac{1}{4 + \frac{1}{3}} = 5 + \frac{3}{13} = \frac{68}{13} have the same numerator!

An application of the result is that we may now turn a backwards recursion into a forewords recursion. That is, [q0,q1,…,qn]=[qn,…,q1,q0]=qn[qn−1,…,q0]+[qn−2,…,q0][q_0,q_1,\dots, q_n] = [q_n, \dots, q_1,q_0] = q_n[q_{n-1}, \dots, q_0] + [q_{n-2}, \dots, q_0] hence if An=[q0,…,qn]A_n = [q_0, \dots, q_n] then An=qnAn−1+An−2A_n = q_n A_{n-1} + A_{n-2} for n≥2n\geq 2. Also the denominator is given by Bn=[q1,…,qn]=qnBn−1+Bn−2B_n = [q_1, \dots, q_n] =q_n B_{n-1} + B_{n-2} for n≥2n\geq 2. We may also set A−1=1,A−2=0A_{-1} = 1, A_{-2} = 0 so this recursion holds for all nn. The advantage now is that extending a continued fraction by one extra partial quotient no longer requires redoing the entire thing from the bottom!

Let α=q0+1q1+1q2+1…+1qn{\alpha}= q_0 + \frac{1}{q_1+ \frac{1}{q_2 + \frac{1}{\dots + \frac{1}{q_n}}}}. The mthm^{th} partial quotient (m≤nm\leq n) for α{\alpha} is given by AmBm=[q0,q1…,qm][q1,…,qm].\frac{A_m}{B_m} = \frac{[q_0, q_1\dots, q_m]}{[q_1,\dots, q_m]}.

Example 4.4. Find the continued fraction for 4321123\frac{4321}{123} and find all of its partial quotients (i.e. it’s convergence).

First, the Euclidean algorithm gives 4321=35⋅123+16123=7⋅16+1116=1⋅11+511=2⋅5+15=5⋅1+0\begin{align*} 4321 & = 35\cdot 123 + 16\\ 123 &= 7\cdot 16 + 11\\ 16 & = 1\cdot 11 + 5\\ 11& = 2\cdot 5 + 1\\ 5 &= 5\cdot 1 + 0 \end{align*} so 4321123=35+16123=35+17+1116=…=35+17+11+12+15.\frac{4321}{123} = 35 + \frac{16}{123} = 35 + \frac{1}{7 + \frac{11}{16}} = \dots = 35 + \frac{1}{7 + \frac{1}{1 + \frac{1}{2 + \frac{1}{5}}}}. Now, the sort way to find the partial quotients is via the following table;

nn qnq_n An=qnAn−1+An−2A_n = q_n A_{n-1} + A_{n-2} Bn=qnBn−1+Bn−2B_n = q_n B_{n-1} + B_{n-2} AnBn\frac{A_n}{B_n}
-2 - 0 1 -
-1 - 1 0 -
0 35 35 1 35
1 7 246 7 246/7
2 1 1(246) + 35 = 281 8 281/8
3 2 2(281) + 246= 808 2(8) + 7 = 23 808/23
4 5 5(808) + 281 = 4321 5(23) + 8 = 123 4321/123

Lemma 4.5. AmBm−Am−1Bm−1=Bm−1Am+Am−1BmBmBm−1=(−1)mBmBm−1\frac{A_m}{B_m} - \frac{A_{m-1}}{B_{m-1}} = \frac{B_{m-1}A_m + A_{m-1}B_m}{B_mB_{m-1}} = \frac{(-1)^m } {B_mB_{m-1}} That is, they alternate in sign.

Proof. By induction, when m=−1m= -1 we have A−1B−2−A−2B−1=1⋅1−0⋅0=(−1)2A_{-1}B_{-2} - A_{-2}B_{-1} = 1\cdot 1 - 0 \cdot 0 = (-1)^2 which is good. Assuming now that the result holds for m−1m-1 and considering the mthm^{th} case (m≥0m\geq 0), then AmBm−1Am−1Bm=(qmAm−1+Am−2)Bm−1−Am−1(qmBm−1+Bm−2)=Am−2Bm−1−Am−1Bm−2=−(Am−1Bm−2−Am−2Bm−1)=(−1)m−1.\begin{align*} A_mB_{m-1}A_{m-1}B_m &= (q_mA_{m-1}+A_{m-2})B_{m-1} - A_{m-1}(q_mB_{m-1} + B_{m-2})\\ &= A_{m-2}B_{m-1} - A_{m-1}B_{m-2}\\ &= - (A_{m-1}B_{m-2}-A_{m-2}B_{m-1}) = (-1)^{m-1}. \end{align*} ◻

Corollary 4.6. AmBm\frac{A_m}{B_m} is in reduced form. That is gcd⁡(Am,Bm)=1\gcd(A_m, B_m) = 1.

Proof. Let gcd⁡(Am,Bm)=d≥1\gcd(A_m, B_m) = d\geq 1 and we have AmBm−1−Am−1Bm=(−1)m−1A_mB_{m-1} - A_{m-1}B_m = (-1)^{m-1}. Since d|Amd|A_m and d|Bmd|B_m then d|AmBm−1−Am−1Bm=(−1)m−1d|A_mB_{m-1} - A_{m-1}B_m = (-1)^{m-1} implying d=1d= 1. ◻

4.2 Infinite continued fractions

Let α∈ℝ∖ℚ{\alpha}\in{\mathbb {R}}\backslash{\mathbb {Q}} (i.e. α{\alpha} is irrational). The procedure α=q0+1α1{\alpha}= q_0 + \frac{1}{{\alpha}_1} with q0∈ℤq_0\in {\mathbb {Z}} and α1>1{\alpha}_1>1 can be repeated on α1{\alpha}_1 and yields a continued fraction for α{\alpha}. After n+1n+1 repetitions of this, one will have α=q0+1q1+1q2+1⋱1qn+1αn+1{\alpha}= q_0 + \frac{1}{q_1+ \frac{1}{q_2 + \frac{1}{\ddots \frac{1}{q_n + \frac{1}{{\alpha}_{n+1}}}}}} and never terminates. That is to say αn+1≠0{\alpha}_{n+1} \neq 0 since α{\alpha} is irrational. Note that for rationals αn+1=∞{\alpha}_{n+1} = \infty. So in this case we write α=[q0,q1,…,qn,αn+1][q1,q2,…,qn,αn+1]{\alpha}= \frac{[q_0, q_1, \dots, q_n, {\alpha}_{n+1}]}{[q_1, q_2, \dots, q_n, {\alpha}_{n+1}]} where [q0,q1,…,qn,αn+1]=αn+1An+An−1 and [q1,…,qn,αn+1]=αn+1Bn+Bn−1[q_0, q_1, \dots, q_n, {\alpha}_{n+1}] = {\alpha}_{n+1}A_n + A_{n-1} \text{ and } [q_1, \dots, q_n, {\alpha}_{n+1} ] = {\alpha}_{n+1}B_n + B_{n-1} and so we could also write α=αn+1An+An−1αn+1Bn+Bn−1.{\alpha}= \frac{{\alpha}_{n+1}A_n + A_{n-1}}{{\alpha}_{n+1}B_n + B_{n-1}}.

Question: How well do convergents AiBi\frac{A_i}{B_i} approximate α{\alpha}? Equivalently, how small is |α−AnBn|\left|{\alpha}- \frac{A_n}{B_n}\right|?

Theorem 4.7. |α−AnBn|<1BnBn+1\left|{\alpha}- \frac{A_n}{B_n}\right|<\frac{1}{B_nB_{n+1}} for all n≥0n\geq 0. Furthermore, this implies |α−AnBn|→0\left|{\alpha}- \frac{A_n}{B_n}\right|\to 0 as n→∞n\to \infty because BnB_n is a monotonically increasing sequence of integers (Bn=qnBn−1+Bn−2>Bn−1B_n = q_n B_{n-1} + B_{n-2}>B_{n-1} ).

Proof. Consider the difference α−AnBn=αn+1An+An−1αn+1Bn+Bn−1−AnBn=αn+1BnAn+An−1Bn−αn+1AnBn−AnBn−1Bn(αn+1Bn+Bn−1)=(−1)nBn(αn+1Bn+Bn−1)<(−1)nBn(qn+1Bn+Bn−1)=(−1)nBnBn+1\begin{align*} {\alpha}- \frac{A_n}{B_n} &= \frac{{\alpha}_{n+1}A_n+ A_{n-1}}{{\alpha}_{n+1}B_n + B_{n-1}} - \frac{A_n}{B_n}\\ &= \frac{{\alpha}_{n+1}B_nA_n + A_{n-1}B_n - {\alpha}_{n+1}A_nB_n - A_n B_{n-1}}{B_n({\alpha}_{n+1}B_n + B_{n-1})}\\ &= \frac{(-1)^n}{B_n({\alpha}_{n+1}B_n+B_{n-1})}\\ &< \frac{(-1)^n}{B_n(q_{n+1}B_n+B_{n-1})}\\ &= \frac{(-1)^n}{B_nB_{n+1}} \end{align*} where the inequality holds because αn+1=qn+1+1αn+2>qn+1{\alpha}_{n+1} = q_{n+1} + \frac{1}{{\alpha}_{n+2}}>q_{n+1} and this yields the desired result. ◻

Another important observation to make is that the sequence given by |α−AnBn|\left|{\alpha}- \frac{A_n}{B_n}\right| is monotonically decreasing. Continued fractions provide best approximations of irrational numbers in the sense that if AnBn\frac{A_n}{B_n} is the nthn^{th} convergent to α{\alpha}, then any other ab∈ℚ\frac{a}{b}\in {\mathbb {Q}} which is closer to α{\alpha} must have b>Bnb>B_n (i.e. larger denominator).

An application of this answers the question “Why are there 12 notes to an octave?” There are 3 constraints here.

1. Desire to modulate (i.e. transpose ratio between successive is constant, say rr),

2. Must capture an octave,

3. Want to capture a perfect 5th5^{th}.

This means3 we want ra=32r^a = \frac{3}{2} for some a∈ℤa\in {\mathbb {Z}}. This implies4 2a/k=3/22^{a/k} =3/2 which can’t be done because this is 2a=(3/2)k2^a = (3/2)^k so 2a+k=3k2^{a+k} = 3^k and violates prime factorization. We should thus find ratios a/ka/k such that 2a/k≈3/22^{a/k} \approx 3/2. Examine 2x=3/22^x = 3/2 whose solution is x=log⁡2(3/2)=0.5849625...x = \log_2(3/2) = 0.5849625... and is irrational. Finding rational numbers close to xx using continued fractions (since they give the best approximations). We find that x=0+11+11+12+12+13+…x = 0 + \frac{1}{1+ \frac{1}{1+ \frac{1}{2+ \frac{1}{2+ \frac{1}{3+ \dots}}}}} and convergents are 0,1,1/2,3/5,7/12,24/410, 1, 1/2, 3/5, 7/12, 24/41 which suggests a 12 note octave with a perfect fifth approximated. So 27/12≈1.4983072^{7/12} \approx 1.498307 and approximates a perfect fifth within 2% of a semitone.

Theorem 4.8. Continued fractions give best approximation to real numbers. That is, if α∈ℝ{\alpha}\in {\mathbb {R}} and AnBn\frac{A_n}{B_n} is the nthn^{th} convergent then |α−ab|<|α−AnBn|\left|{\alpha}- \frac{a}{b}\right|<\left|{\alpha}- \frac{A_n}{B_n}\right| implies b>Bnb>B_n.

Proof. Even convergence are increasing and odd convergence are decreasing (because of the (−1)n(-1)^n found in the differences). Suppose that nn is even and that a/b∈ℚa/b\in {\mathbb {Q}} were closer to α{\alpha}. Then a/b∈(AnBn,α+α−AnBn)⊂(AnBn,An−1Bn−1)a/b\in \left(\frac{A_n}{B_n}, {\alpha}+{\alpha}-\frac{A_n}{B_n}\right) \subset \left(\frac{A_n}{B_n}, \frac{A_{n-1}}{B_{n-1}}\right). Now, (An−1Bn−1−ab)+(ab−AnBn)=(An−1Bn−1−AnBn)=(−1)nBnBn−1=1BnBn−1\left(\frac{A_{n-1}}{B_{n-1}} - \frac{a}{b}\right) + \left(\frac{a}{b}- \frac{A_n}{B_n}\right) = \left(\frac{A_{n-1}}{B_{n-1}} - \frac{A_n}{B_n}\right) = \frac{(-1)^n}{B_nB_{n-1}} = \frac{1}{B_nB_{n-1}} since nn is even. This implies (expanding the left hand side) that bAn−1−aBn−1bBn−1+aBn−AnbbBn=1BnBn−1\frac{bA_{n-1} - aB_{n-1}}{bB_{n-1}} + \frac{aB_n - A_nb}{bB_n} = \frac{1}{B_nB_{n-1}} Hence, then 1bBn−1+1bBn≤1BnBn−1\frac{1}{bB_{n-1}} + \frac{1}{bB_n} \leq \frac{1}{B_nB_{n-1}} which implies b≥Bn+Bn−1>Bnb\geq B_n+B_{n-1} >B_n as claimed. ◻

4.2.1 Periodic continued fractions

Let us begin with an example, α=1+12+13+11+12+13+1⋱=1+12+13+1α=10α+37α+2{\alpha}= 1+\frac{1}{2+ \frac{1}{3 + \frac{1}{1 + \frac{1}{2 + \frac{1}{3 + \frac{1}{\ddots}}}}}} = 1+\frac{1}{2+ \frac{1}{3 + \frac{1}{{\alpha}}}} = \frac{10{\alpha}+ 3}{7{\alpha}+ 2} This yields the quadratic equation for α{\alpha} given by 7α2−8α−3=07{\alpha}^2 - 8{\alpha}-3 = 0 and so implies α=4±377{\alpha}= \frac{4\pm \sqrt{37}}{7}, but α>1{\alpha}>1 so we take α=4+377{\alpha}= \frac{4 +\sqrt{37}}{7}. Also, we may write α=[1,2,3,α][2,3,α]{\alpha}= \frac{[1,2,3,{\alpha}]}{[2,3,{\alpha}]} which implies α=α[1,2,3]+[1,2]α[2,3]+[2]{\alpha}= \frac{{\alpha}[1,2,3] + [1,2]}{{\alpha}[2,3] + [2]}.

Notice, in general that α=αn+1An+An−1αBn+Bn−1{\alpha}= \frac{{\alpha}_{n+1}A_n + A_{n-1}}{{\alpha}B_n + B_{n-1}} and is purely periodic when α=αn+1{\alpha}= {\alpha}_{n+1} for some n+1n+1. In the case of pure periodicity, then α{\alpha} satisfies a quadratic equation with integer coefficients. For example, from above A0B0=11,A1B1=32,A2B2=107\frac{A_0}{B_0} = \frac{1}{1}, \frac{A_1}{B_1} = \frac{3}{2}, \frac{A_2}{B_2} = \frac{10}{7} implying that α=αA2+A1αB2+B1=10α+37α+2{\alpha}= \frac{{\alpha}A_2 + A_1}{{\alpha}B_2 + B_1} = \frac{10{\alpha}+ 3}{7{\alpha}+ 2}.

Theorem 4.9. α{\alpha} periodic implies that αn+1=α{\alpha}_{n+1} = {\alpha} eventually.

Definition 4.10.

  1. α{\alpha} is called a quadratic irrational if it is an irrational root of a quadratic equation with integer coefficients (i.e. aα2+bα+c=0a{\alpha}^2 + b{\alpha}+ c = 0 for a,b,c∈ℤa,b,c\in {\mathbb {Z}})

  2. If α{\alpha} is a root of ax2+bx+c=0ax^2 + bx+c =0 then its conjugate, denoted by α′{\alpha}' is the other root.

  3. A quadratic irrational is called reduced if α>1{\alpha}>1 and its conjugate satisfies −1<α′<0-1<{\alpha}'<0.

Theorem 4.11. α{\alpha} has a purely periodic continued fraction if and only if α{\alpha} is reduced.

Proof. Suppose first that α{\alpha} has a purely periodic continued fraction so that α=q0+1q1+1⋱+1qn+1α=αAn+An−1αBn+Bn−1{\alpha}= q_0 + \frac{1}{q_1+ \frac{1}{\ddots + \frac{1}{q_n + \frac{1}{{\alpha}}}}} = \frac{{\alpha}A_n + A_{n-1}}{{\alpha}B_n + B_{n-1}} which give a quadratic irrational (we know it irrational since the continued fraction doesn’t terminate). Consider β{\beta} obtained by reversing the period of α{\alpha}. That is, β=qn+1qn−1+1⋱+1q0+1β=[qn,…,q0,β][qn−1,…,q0,β]=β[qn,…,q0]+[qn,…,q1]β[qn−1,…,q0]+[qn−1,…,q1]=βAn+BnβAn−1+Bn−1.{\beta}= q_n + \frac{1}{q_{n-1}+ \frac{1}{\ddots + \frac{1}{q_0 + \frac{1}{{\beta}}}}} = \frac{[q_n, \dots, q_0, {\beta}]}{[q_{n-1}, \dots, q_0, {\beta}]} = \frac{{\beta}[q_n, \dots, q_0] + [q_n, \dots, q_1]}{{\beta}[q_{n-1}, \dots, q_0] + [q_{n-1}, \dots, q_1]} = \frac{{\beta}A_n + B_n}{{\beta}A_{n-1} + B_{n-1}}. So, α,β{\alpha}, {\beta} satisfy α=αAn+An−1αBn+Bn−1,β=βAn+BnβAn−1+Bn−1{\alpha}= \frac{{\alpha}A_n + A_{n-1}}{{\alpha}B_n + B_{n-1}}, {\beta}= \frac{{\beta}A_n + B_n}{{\beta}A_{n-1} + B_{n-1}} which are equivalent to Bnα2+(Bn−1−An)α−An−1=0B_n{\alpha}^2 + (B_{n-1}- A_n){\alpha}- A_{n-1} = 0 and An−1β2+(Bn−1−An)β−Bn=0A_{n-1}{\beta}^2 + (B_{n-1} - A_n) {\beta}- B_n = 0 multiplying the second equation by −1β2\frac{-1}{{\beta}^2} then becomes Bn(−1β2)+(Bn−1−An)(−1β2)−Bn=0B_n\left(\frac{-1}{{\beta}^2}\right) + (B_{n-1} - A_n)\left(\frac{-1}{{\beta}^2}\right) - B_n = 0 meaning that α{\alpha} and −1/β-1/{\beta} are conjugates (i.e. distinct roots of the same quadratic equation). Now, β=qn+1…>qn≥1{\beta}= q_n + \frac{1}{\dots}>q_n \geq 1 implies −1<−1/β<0-1<-1/{\beta}<0 so α{\alpha} is reduced.

Conversely, suppose α{\alpha} is reduced so that it is a quadratic irrational with α>1{\alpha}>1 and α′∈(−1,0){\alpha}'\in (-1, 0). More precisely this means aα2+bα+c=0a{\alpha}^2 + b{\alpha}+ c =0 for some a,b,c∈ℤa, b,c\in {\mathbb {Z}} so that α=−b+b2−4ac2a=P+DQ{\alpha}= \frac{-b+ \sqrt{b^2- 4ac}} {2a} = \frac{P + \sqrt{D}}{Q}. So D=b2−4acD = b^2 - 4ac is square free and positive, P=−bP = -b and Q=2aQ = 2a while α′=P−DQ{\alpha}' = \frac{P-\sqrt{D}}{Q}.

Lemma 4.12. α{\alpha} reduced implies

(i) Both P,Q>0P, Q>0,

(ii) Q|P2−DQ|P^2 - D, and

(iii) P<D,Q<2DP<\sqrt{D}, Q<2\sqrt{D}.

proof: For (ii), observe P2−D=b2−b2+4ac=4ac=2a⋅2cP^2 - D = b^2 - b^2 + 4ac = 4ac = 2a\cdot 2c and Q=2aQ = 2a. For (i) Q>0Q>0 by assumption and α>1,α′>−1{\alpha}>1, {\alpha}'>-1 means α+α′>0{\alpha}+ {\alpha}'>0 which means 2PQ>0\frac{2P}{Q}>0 so P>0P>0 since Q>0Q>0. Finally, for (iii) α>1{\alpha}>1 so P+DQ>1\frac{P+\sqrt{D}}{Q}>1 which implies Q<P+D<2DQ<P+\sqrt{D}<2\sqrt{D} since P<DP<\sqrt{D} because α′=P−DQ<0{\alpha}' = \frac{P-\sqrt{D}}{Q}<0 meaning P<DP<\sqrt{D}.

As second lemma states;

Lemma 4.13. Consider the continued fraction from the algorithm α=q0+1α1{\alpha}= q_0 + \frac{1}{{\alpha}_1} where q0q_0 is the integer part of α{\alpha}. If α{\alpha} is reduced then so is α1{\alpha}_1. Furthermore, α1{\alpha}_1 takes the form α1=P+DQ1{\alpha}_1 = \frac{P_+\sqrt{D}}{Q_1} for the same DD as α{\alpha} and P1,Q1∈ℤP_1, Q_1\in {\mathbb {Z}}.

proof: Let α=q0+1α1{\alpha}= q_0 + \frac{1}{{\alpha}_1} so that α1=α−q0=P+DQ−q0=(P−Qq0)+DQ{\alpha}_1 = {\alpha}- q_0 = \frac{P+\sqrt{D}}{Q} - q_0 = \frac{(P-Qq_0) + \sqrt{D}}{Q}. Declare that −P1=P−Qq0-P_1=P-Qq_0 so to say α1=Q−P1+D{\alpha}_1 = \frac{Q}{-P_1+\sqrt{D}}. Simplifying this gives α1=QP12−D⋅(−P1−D)=P1+DD−P12Q=P1+DQ1{\alpha}_1 = \frac{Q}{P_1^2-D}\cdot (-P_1-\sqrt{D}) = \frac{P_1 + \sqrt{D}}{\frac{D-P_1^2}{Q}} = \frac{P_1+\sqrt{D}}{Q_1} since D−P12=D−P2−2PQq0+Q2q0D- P_1^2 = D-P^2 - 2PQq_0+Q^2q_0 so Q|D−P12Q|D-P_1^2 and Q1∈ℤQ_1\in {\mathbb {Z}}.

Apparently this is the end of the proof. ◻

An application of this is to provide a continued fraction for N∈ℕ∖{perfect squares}\sqrt{N}\in {\mathbb {N}}\backslash\{\text{perfect squares}\}.

Claim: N+q0\sqrt{N}+q_0 where q0=⌊N⌋q_0 = \lfloor\sqrt{N}\rfloor is purely periodic.

Proof. 1. N+q0\sqrt{N} + q_0 is a quadratic irrational since α=N+q0{\alpha}= \sqrt{N}+q_0 which implies (α−q0)2=N({\alpha}-q_0)^2 = N so that α2−2q0α+q02−N=0{\alpha}^2 - 2q_0{\alpha}+ q_0^2 - N = 0.

2. N+q0>1\sqrt{N} + q_0 >1

3.q0−N∈(0,1)q_0 - \sqrt{N}\in (0,1) since q0=⌊N⌋q_0 = \lfloor \sqrt{N}\rfloor which implies N∈(q0,q0+1)\sqrt{N}\in (q_0 , q_0 +1) and −N∈(−q0−1,−q0)-\sqrt{N}\in (-q_0-1, -q_0) so that −N+q0∈(−1,0)-\sqrt{N} + q_0\in (-1, 0). ◻

4.3 Pell’s equations

These come up when trying to find units in real quadratic fields. Let NN be a positive integer which is not a square. Pell’s equation is x2−Ny2=1.x^2 - Ny^2 = 1. and we wish to find positive integer solutions x,y∈ℤx,y\in{\mathbb {Z}} to the equation 1=(x−Ny)(x+Ny)1 = (x-\sqrt{N}y)(x+\sqrt{N}y). This implies (xy−N)=1y(x+Ny)<1y(Ny+Ny)=12y2N\left(\frac{x}{y} - \sqrt{N}\right) = \frac{1}{y(x + \sqrt{N}y)}<\frac{1}{y(\sqrt{N}y + \sqrt{N}y)} = \frac{1}{2y^2\sqrt{N}} where the inequality holds since x2=Ny2+1>Ny2x^2 = Ny^2 + 1>Ny^2 so x>Nyx>\sqrt{N}y.

So a pair of integer solutions to x2−Ny2=1x^2 - Ny^2 = 1 give an approximation to N\sqrt{N}. Namely |xy−N|<12y2N\left| \frac{x}{y} - \sqrt{N}\right|<\frac{1}{2y^2 \sqrt{N}} which beats the typical convergent to N\sqrt{N} by quite a bit. We learned that continued fractions give best approximations to reals. This suggests looking at the continued fraction for N\sqrt{N}, but only certain types of convergence will give this tight of an approximation.

Consider AnBn,An−1Bn−1\frac{A_n}{B_n}, \frac{A_{n-1}}{B_{n-1}} (the two convergence that appear before the 2q02q_0 term)

N=q0,q1,q2,…,qn,2q0¯=αn+1An+An−1αn+1Bn+Bn−1,αn+1=2q0+1q1+1⋱+1qn+12q0+1⋱=(N+q0)An+An−1(N+q0)Bn+Bn−1\begin{align*} \sqrt{N} &= q_0, \overline{q_1, q_2, \dots, q_n, 2q_0}\\ &= \frac{{\alpha}_{n+1}A_n + A_{n-1}}{{\alpha}_{n+1}B_n + B_{n-1}}, \qquad {\alpha}_{n+1}= 2q_0 + \frac{1}{q_1 + \frac{1}{\ddots + \frac{1}{q_n+ \frac{1}{2q_0+ \frac{1}{\ddots}}}}}\\ &= \frac{(\sqrt{N} + q_0)A_n + A_{n-1}}{(\sqrt{N} + q_0)B_n + B_{n-1}} \end{align*} This implies NBn+(q0Bn+Bn−1)N=q0An+An−1+AnNNB_n + (q_0 B_n+B_{n-1})\sqrt{N} = q_0A_n + A_{n-1} + A_n\sqrt{N} and comparing coefficients gives NBn=q0An+An−1NB_n = q_0A_n + A_{n-1} and An=q0Bn+Bn−1A_n = q_0 B_n + B_{n-1} meaning An−1=NBn−q0AnA_{n-1} = NB_n - q_0A_n and Bn−1=An−q0BnB_{n-1} = A_n - q_0 B_n. Now, AnBn−1−BnAn−1=(−1)n−1A_nB_{n-1} - B_nA_{n-1} = (-1)^{n-1} so An(An−q0Bn)−Bn(NBn−q0An)=(−1)n−1A_n(A_n - q_0 B_n) - B_n(NB_n - q_0A_n) = (-1)^{n-1} and hence An2−NBn2=(−1)n−1.A_n^2 - NB_n^2 = (-1)^{n-1}. So when nn is odd, this is a solution to Pell’s equations. If nn is even, we go up by n+1n+1 convergence to A2n+1B2n+1,A2nB2n\frac{A_{2n+1}}{B_{2n+1}}, \frac{A_{2n}}{B_{2n}} and the proof is the same. In general we get Akn+k−12−NBkn+k−12=(−1)kn+k−2A_{kn+k-1}^2 - N B_{kn+k - 1}^2 = (-1)^{kn+k - 2} and kn+k−2≡k(n+1)≡0mod⁡2kn+k -2 \equiv k(n+1)\equiv 0\mod 2 if and only if nn is odd or kk is even.

5 Partitions

How many ways can we add up to an integer from a given set? Some classical problems involving this are sums of positive integers, sums of squares, cubes, etc. and the Goldbach conjecture about sums of primes.

An easy problem; how many ways are there to add to n∈ℕn\in {\mathbb {N}} using positive integers where the order is taken into consideration? Place nn dots on the page in a row, there are 2n−12^{n-1} ways to insert a barrier or not between each of these dots. This is equivalent to partitioning nn into a sum of positive integers where order counts. Hence c(n)c(n), the number of ways to write nn as a sum of positive integers, is 2n−12^{n-1}.

If order doesn’t count, then c(n)=[xn]∏i≥1(1−xi)−1c(n) = [x^n] \prod_{i\geq 1} (1-x^i)^{-1}. The following result relates partitions to pentagonal numbers.

Theorem 5.1 (Euler’s Pentagonal Number Theorem). ∏n=1∞(1−xn)=∑k=−∞∞(−1)kxω(n)=1+∑k=1[∞(−1)k(xk(3k+1)/2+xk(3k−1)/2)\prod_{n=1}^\infty (1-x^n) = \sum_{k=-\infty}^\infty (-1)^kx^{{\omega}(n)} = 1 + \sum_{k=1}^[\infty (-1)^k(x^{k(3k+1)/2} + x^{k(3k-1)/2}) where ω(n)=3n2−n2≥0{\omega}(n) = \frac{3n^2 - n}{2}\geq 0 are called pentagonal numbers.

Hardy and Littlewood show using ∏i≥1(1−xi)−1=∑p(n)xn\prod_{i\geq 1}(1-x^i)^{-1} = \sum p(n)x^n with p(n)≈eπ(2/3)12n4n3p(n) \approx \frac{e^{\pi(2/3)^{\frac{1}{2}}\sqrt{n}}}{4n\sqrt{3}}. Ramanujan wrote, with q=e2πizq = e^{2\pi i z} and Δ(z)=q∏1∞(1−qm)24=∑n=1∞τ(n)qn\Delta(z) = q\prod_{1}^\infty (1-q^m)^{24} = \sum_{n=1}^\infty \tau(n)q^n and τ(ab)=τ(a)τ(b)\tau(ab) = \tau(a) \tau(b) when a,ba,b are coprime. Now, Δ(−1/z)=z12Δ(z)\Delta(-1/z) = z^{12}\Delta(z) is the first example of an integer weight modular form.

Let rk(n)r_k(n) be the number of ways of writing n∈ℤn\in {\mathbb {Z}} as a sum of kk-squares (allowing negatives and zeros). One finds that r2(n)=4(d1(n)−d3(n))r_2(n) = 4(d_1(n) - d_3(n)) where dk(n)d_k(n) is the number of divisors of nn congruent to kk modulo 4. Note that r2(n)≥4r_2(n)\geq 4 if nn does not have a prime of the form 4k+34k+3 raised to an odd power in its prime factorization.

Furthermore, r4(n)={8∑d|nd, if n≥8 is odd24∑d|n, oddd, if n≥8 is evenr_4(n) = \begin{cases}8\sum_{d|n}d, \text{ if } n\geq 8 \text{ is odd}\\ 24\sum_{d|n, \text{ odd}} d, \text{ if } n\geq 8\text{ is even}\end{cases} which implies all positive integers mm can be expressed as the sum of four squares.

Theorem 5.2 (Euler). Let p=4k+1p = 4k+1 be prime. Then pp can be written as the sum of squares.

Proof. With p≡1mod⁡4p\equiv 1\mod 4 the the congruence can be solved by z2≡−1mod⁡pz^2 \equiv -1\mod p for some 1≤z<p1\leq z<p.

Now, p|z2+1p|z^2 + 1 implies z2+1=mpz^2 + 1 = mp for some m∈ℤm\in {\mathbb {Z}} with 1≤m<p1\leq m <p. If mpmp can be written as the sum of two squares with 1≤m<p1\leq m <p then there exists an rr with 1≤r<m1\leq r<m such that rp=x12+y12rp = x_1^2 + y_1^2. Repeat this process until r=1r = 1. To demonstrate that this is true, reduce x,yx,y modulo mm chosen to lie in the interval (−m/2,m/2)(-m/2, m/2). That is x≡u,y≡vmod⁡mx\equiv u, y\equiv v\mod m with both −m/2<u,v<m/2-m/2<u,v<m/2. Now u2+v2≡x2+y2≡0mod⁡mu^2 + v^2 \equiv x^2 +y^2 \equiv 0 \mod m where u2+v2=rmu^2 + v^2 = rm for some r≥0r\geq 0. Since m≥1m\geq 1 and the left hand side is positive, this furthermore means that r≠0r\neq 0 because otherwise u=v=0u = v = 0, m|x,m|ym|x, m|y so m2|x2+y2=mpm^2|x^2 + y^2 = mp but this implies m|pm|p (a contradiction).

Thus, u2+v2=rmu^2 + v^2 = rm with r≥1r\geq 1. Now, r=u2+v2m≤m24+m24m=m2<mr= \frac{u^2 + v^2}{m}\leq \frac{\frac{m^2}{4} + \frac{m^2}{4}}{m} = \frac{m}{2}<m so r<mr<m.

(mp)(rm)=(x2+y2)(u2+v2)=(xu+yv)2+(xv−yu)2(mp)(rm) = (x^2 + y^2) (u^2+ v^2) = (xu+yv)^2 + (xv-yu)^2 by Fibonacci. Thus, a product of squares is a sum of two squares. xu+yv≡x2+y2≡0mod⁡mxu+yv \equiv x^2 + y^2\equiv 0\mod m and xv−yu=xy−yxmod⁡mxv-yu = xy - yx\mod m meaning that m2|(xu+yv)2m^2 |(xu+yv)^2 and m2|(xu−yu)2m^2|(xu-yu)^2 so that rp=x12+y12rp = x_1^2 + y_1^2. ◻


  1. although I think this should be verified↩︎

  2. for this, one requires a2≡1mod⁡p⇒p|a2−1=(a+1)(a−1)a^2\equiv 1 \mod p\Rightarrow p|a^2-1 = (a+1)(a-1) so that a≡±1mod⁡pa \equiv \pm 1 \mod p↩︎

  3. I do not understand any of this↩︎

  4. why?↩︎