\documentclass[numbers=enddot,12pt,final,onecolumn,notitlepage]{scrartcl}%
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[all,cmtip]{xy}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{framed}
\usepackage{comment}
\usepackage{color}
\usepackage[breaklinks=True]{hyperref}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{needspace}
\usepackage{tabls}
\usepackage{tikz}
\usepackage{bbding}
%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{LastRevised=Thursday, February 16, 2023 18:38:06}
%TCIDATA{SuppressPackageManagement}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Language=American English}
%BeginMSIPreambleData
\providecommand{\U}[1]{\protect\rule{.1in}{.1in}}
%EndMSIPreambleData
\usetikzlibrary{arrows.meta}
\usetikzlibrary{chains}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\newcounter{exer}
\newcounter{exera}
\theoremstyle{definition}
\newtheorem{theo}{Theorem}[subsection]
\newenvironment{theorem}[1][]
{\begin{theo}[#1]\begin{leftbar}}
{\end{leftbar}\end{theo}}
\newtheorem{lem}[theo]{Lemma}
\newenvironment{lemma}[1][]
{\begin{lem}[#1]\begin{leftbar}}
{\end{leftbar}\end{lem}}
\newtheorem{prop}[theo]{Proposition}
\newenvironment{proposition}[1][]
{\begin{prop}[#1]\begin{leftbar}}
{\end{leftbar}\end{prop}}
\newtheorem{defi}[theo]{Definition}
\newenvironment{definition}[1][]
{\begin{defi}[#1]\begin{leftbar}}
{\end{leftbar}\end{defi}}
\newtheorem{remk}[theo]{Remark}
\newenvironment{remark}[1][]
{\begin{remk}[#1]\begin{leftbar}}
{\end{leftbar}\end{remk}}
\newtheorem{coro}[theo]{Corollary}
\newenvironment{corollary}[1][]
{\begin{coro}[#1]\begin{leftbar}}
{\end{leftbar}\end{coro}}
\newtheorem{conv}[theo]{Convention}
\newenvironment{convention}[1][]
{\begin{conv}[#1]\begin{leftbar}}
{\end{leftbar}\end{conv}}
\newtheorem{quest}[theo]{Question}
\newenvironment{question}[1][]
{\begin{quest}[#1]\begin{leftbar}}
{\end{leftbar}\end{quest}}
\newtheorem{warn}[theo]{Warning}
\newenvironment{warning}[1][]
{\begin{warn}[#1]\begin{leftbar}}
{\end{leftbar}\end{warn}}
\newtheorem{conj}[theo]{Conjecture}
\newenvironment{conjecture}[1][]
{\begin{conj}[#1]\begin{leftbar}}
{\end{leftbar}\end{conj}}
\newtheorem{exam}[theo]{Example}
\newenvironment{example}[1][]
{\begin{exam}[#1]\begin{leftbar}}
{\end{leftbar}\end{exam}}
\newtheorem{exmp}[exer]{Exercise}
\newenvironment{exercise}[1][]
{\begin{exmp}[#1]\begin{leftbar}}
{\end{leftbar}\end{exmp}}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\begin{small}}{\end{small}}
\iffalse
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{convention}[1][Convention]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{question}[1][Question]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\fi
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}
\newcommand\arxiv[1]{\href{http://www.arxiv.org/abs/#1}{\texttt{arXiv:#1}}}
\setlength\tablinesep{3pt}
\setlength\arraylinesep{3pt}
\setlength\extrarulesep{3pt}
\setlength\textheight{22.5cm}
\setlength\textwidth{14.8cm}
\newenvironment{verlong}{}{}
\newenvironment{vershort}{}{}
\newenvironment{noncompile}{}{}
\excludecomment{verlong}
\includecomment{vershort}
\excludecomment{noncompile}
\newcommand{\defn}[1]{{\color{darkred}\emph{#1}}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\KK}{\mathbb{K}}
\newcommand{\set}[1]{\left\{ #1 \right\}}
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\tup}[1]{\left( #1 \right)}
\newcommand{\ive}[1]{\left[ #1 \right]}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\are}{\ar@{-}}
\newcommand{\arebi}[1][]{\ar@{<-}@/_/[#1] \ar@/^/[#1]}
\newcommand{\of}{\text{ of }}
\newtheoremstyle{plainsl}
{8pt plus 2pt minus 4pt}
{8pt plus 2pt minus 4pt}
{\slshape}
{0pt}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}
\theoremstyle{plainsl}
\ihead{Lecture 11, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 11: Elementary number theory}

\textbf{website:}
\texttt{\href{https://www.cip.ifi.lmu.de/~grinberg/t/23wd}{\texttt{https://www.cip.ifi.lmu.de/\symbol{126}%
grinberg/t/23wd}}}

\setcounter{section}{2}

\section{Elementary number theory}

\setcounter{subsection}{5}

\subsection{Prime numbers (cont'd)}

\setcounter{subsubsection}{5}

\setcounter{theo}{7}

\subsubsection{$p$-valuations (cont'd)}

Recall the last definition from Lecture 10:

\begin{definition}
\label{def.ent.prime.vpn-repeat}Let $p$ be a prime. \medskip

\textbf{(a)} Let $n$ be a nonzero integer. Then, $v_{p}\left(  n\right)  $
shall denote the largest $m\in\mathbb{N}$ such that $p^{m}\mid n$. (Thus,
$v_{p}\left(  n\right)  $ is the number of times that you can divide $n$ by
$p$ without getting a non-integer.)

This number $v_{p}\left(  n\right)  $ will be called the $p$%
\textbf{-valuation} (or the $p$\textbf{-adic valuation}) of $n$. \medskip

\textbf{(b)} In order to have $v_{p}\left(  n\right)  $ defined for all
integers $n$ (as opposed to just for nonzero $n$), we also define
$v_{p}\left(  0\right)  $ to be $\infty$ (because $0$ can be divided by $p$ an
arbitrary number of times without any changes). This symbol $\infty$ is not an
actual number, but we shall pretend that it behaves like a number at least in
some regards. In particular, we will eventually add or compare it to other
numbers. In doing so, we shall follow the rules that%
\begin{align*}
k+\infty &  =\infty+k=\infty\ \ \ \ \ \ \ \ \ \ \text{for all }k\in
\mathbb{Z};\\
\infty+\infty &  =\infty;\\
k  &  <\infty\text{ and }\infty>k\ \ \ \ \ \ \ \ \ \ \text{for all }%
k\in\mathbb{Z};\\
\max\left\{  \infty,k\right\}   &  =\max\left\{  k,\infty\right\}
=\infty\ \ \ \ \ \ \ \ \ \ \text{for all }k\in\mathbb{Z};\\
\min\left\{  \infty,k\right\}   &  =\min\left\{  k,\infty\right\}
=k\ \ \ \ \ \ \ \ \ \ \text{for all }k\in\mathbb{Z}.
\end{align*}
Thus, $\infty$ acts like a \textquotedblleft mythical number that is larger
than any actual number\textquotedblright. We can keep up this charade as long
as we only add and compare, but never subtract $\infty$ from anything (since
$1+\infty=\infty$ would turn into $1=0$ if you subtracted $\infty$).
\end{definition}

Here are some examples:

\begin{itemize}
\item We have%
\begin{align*}
v_{3}\left(  99\right)   &  =2\ \ \ \ \ \ \ \ \ \ \left(  \text{since }%
3^{2}\mid99\text{ but }3^{3}\nmid99\right)  ;\\
v_{3}\left(  98\right)   &  =0\ \ \ \ \ \ \ \ \ \ \left(  \text{since }%
3^{0}\mid98\text{ but }3^{1}\nmid98\right)  ;\\
v_{3}\left(  96\right)   &  =1\ \ \ \ \ \ \ \ \ \ \left(  \text{since }%
3^{1}\mid96\text{ but }3^{2}\nmid96\right)  ;\\
v_{3}\left(  0\right)   &  =\infty.
\end{align*}

\end{itemize}

We can restate the definition of $v_{p}\left(  n\right)  $ in yet another way:
If $p$ is a prime and $n$ is a positive integer, then $v_{p}\left(  n\right)
$ is the number of zeroes at the end of the base-$p$ representation of the
number $n$. For example, the base-$2$ representation of the number $344$ is
$101011000$, which has three zeroes at its end (the other zeroes don't
count!), so that $v_{2}\left(  344\right)  =3$.

Note that Definition \ref{def.ent.prime.vpn-repeat} can be generalized to any
positive integer $p>1$ (prime or not). But most of the useful properties of
$p$-valuations hold only when $p$ is prime.

\bigskip

Let us now discuss some basic properties of $p$-valuations. We begin with a
lemma that is almost trivial, but quite helpful:

\begin{lemma}
\label{lem.ent.vp.equivalence}Let $p$ be a prime. Let $i\in\mathbb{N}$ and
$n\in\mathbb{Z}$. Then, $p^{i}\mid n$ if and only if $v_{p}\left(  n\right)
\geq i$.
\end{lemma}

\begin{proof}
If $n=0$, then this is clear (because in this case, we have both $p^{i}%
\mid0=n$ and $v_{p}\left(  n\right)  =v_{p}\left(  0\right)  =\infty\geq i$).

It remains to deal with the case $n\neq0$. In this case, $v_{p}\left(
n\right)  $ is defined as the largest $m\in\mathbb{N}$ such that $p^{m}\mid
n$. Thus, in this case, we have $p^{i}\mid p^{v_{p}\left(  n\right)  }\mid n$
whenever $i\leq v_{p}\left(  n\right)  $, whereas $p^{i}\nmid n$ whenever
$i>v_{p}\left(  n\right)  $. In other words, we have $p^{i}\mid n$ if and only
if $v_{p}\left(  n\right)  \geq i$. Thus, Lemma \ref{lem.ent.vp.equivalence}
is proved in this case as well.
\end{proof}

Recall some standard notations: For any two numbers $x$ and $y$, we let
$\min\left\{  x,y\right\}  $ denote the smaller of these two numbers, and we
let $\max\left\{  x,y\right\}  $ denote the larger of these two numbers. More
generally, if $S$ is a set of numbers, then $\min S$ means the smallest
element of $S$ (if it exists), and $\max S$ means the largest element of $S$
(if it exists).

Now, we can state a bunch of rather important properties of $p$-valuations:

\begin{theorem}
[basic properties of $p$-valuations]\label{thm.ent.vp.vpab}Let $p$ be a prime. Then:

\textbf{(a)} We have $v_{p}\left(  ab\right)  =v_{p}\left(  a\right)
+v_{p}\left(  b\right)  $ for any $a,b\in\mathbb{Z}$.

\textbf{(b)} We have $v_{p}\left(  a+b\right)  \geq\min\left\{  v_{p}\left(
a\right)  ,\ v_{p}\left(  b\right)  \right\}  $ for any $a,b\in\mathbb{Z}$.

\textbf{(c)} We have $v_{p}\left(  1\right)  =0$.

\textbf{(d)} We have $v_{p}\left(  p\right)  =1$.

\textbf{(e)} We have $v_{p}\left(  q\right)  =0$ for any prime $q\neq p$.
\end{theorem}

\begin{proof}
\textbf{(a)} Let $a,b\in\mathbb{Z}$. We must prove that $v_{p}\left(
ab\right)  =v_{p}\left(  a\right)  +v_{p}\left(  b\right)  $.

If $a=0$, then this is saying that $\infty=\infty+v_{p}\left(  b\right)  $,
which follows from our rules for $\infty$ (specifically, from the rules saying
that $\infty+k=\infty$ for all $k\in\mathbb{Z}$ and that $\infty+\infty
=\infty$). Likewise, we can prove our claim if $b=0$.

It thus remains to handle the case when neither $a$ nor $b$ is $0$. So let us
consider this case. Since $a$ and $b$ are nonzero, the numbers $v_{p}\left(
a\right)  $ and $v_{p}\left(  b\right)  $ are nonnegative integers. Let us
call give them names: We set%
\[
n=v_{p}\left(  a\right)  \ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ m=v_{p}\left(  b\right)  .
\]


Thus, $p^{n}\mid a$ and $p^{m}\mid b$. In other words, there are integers $x$
and $y$ such that $a=p^{n}x$ and $b=p^{m}y$. Consider these $x$ and $y$.

If we had $p\mid x$, then we would readily obtain $p^{n+1}\mid a$ (because
$p\mid x$ entails that $x=pz$ for some integer $z$, and thus this integer $z$
must satisfy $a=p^{n}\underbrace{x}_{=pz}=p^{n}pz=p^{n+1}z$) and therefore
$v_{p}\left(  a\right)  \geq n+1$ (by Lemma \ref{lem.ent.vp.equivalence},
applied to $n+1$ and $a$ instead of $i$ and $n$), which would contradict
$v_{p}\left(  a\right)  =n<n+1$. Thus, we cannot have $p\mid x$. For similar
reasons, we cannot have $p\mid y$.

However, multiplying $a=p^{n}x$ with $b=p^{m}y$, we obtain $ab=p^{n}x\cdot
p^{m}y=p^{n+m}xy$, and thus $p^{n+m}\mid ab$. Therefore, $v_{p}\left(
ab\right)  \geq n+m$ (by Lemma \ref{lem.ent.vp.equivalence}, applied to $ab$
and $n+m$ instead of $n$ and $i$).

Now, we shall show that this inequality is an equality. To do so, we must show
that $p^{n+m+1}\nmid ab$.

To prove this, we assume the contrary. Thus, $p^{n+m+1}\mid ab=p^{n+m}xy$.
Dividing both sides of this divisibility by $p^{n+m}$, we obtain $p\mid xy$.

However, the prime divisor separation theorem (Theorem 3.6.5 in Lecture 10)
says that if the prime number $p$ divides a product of two integers, then it
must divide one of these two integers. Therefore, from $p\mid xy$, we obtain
either $p\mid x$ or $p\mid y$ (since $x$ and $y$ are integers). But this
contradicts the fact that we cannot have $p\mid x$ and we cannot have $p\mid
y$. This contradiction shows that our assumption must have been wrong. Thus,
we have shown that $p^{n+m+1}\nmid ab$.

So we know that $p^{n+m}\mid ab$ but $p^{n+m+1}\nmid ab$. In other words, the
largest $i\in\mathbb{N}$ that satisfies $p^{i}\mid ab$ is $n+m$. In other
words, $v_{p}\left(  ab\right)  =n+m$ (by the definition of $v_{p}\left(
ab\right)  $). Since $n=v_{p}\left(  a\right)  $ and $m=v_{p}\left(  b\right)
$, we can rewrite this as $v_{p}\left(  ab\right)  =v_{p}\left(  a\right)
+v_{p}\left(  b\right)  $. This proves Theorem \ref{thm.ent.vp.vpab}
\textbf{(a)}.\medskip

\textbf{(b)} Let $a,b\in\mathbb{Z}$. We must prove that $v_{p}\left(
a+b\right)  \geq\min\left\{  v_{p}\left(  a\right)  ,\ v_{p}\left(  b\right)
\right\}  $.

If $\min\left\{  v_{p}\left(  a\right)  ,\ v_{p}\left(  b\right)  \right\}
=\infty$, then this inequality boils down to $\infty\geq\infty$ (because
$\min\left\{  v_{p}\left(  a\right)  ,\ v_{p}\left(  b\right)  \right\}
=\infty$ yields $v_{p}\left(  a\right)  =\infty$ and $v_{p}\left(  b\right)
=\infty$, so that $a=0$ and $b=0$, and thus $a+b=0$ as well, which in turn
leads to $v_{p}\left(  a+b\right)  =\infty$), which is true.

Thus, it remains to handle the case when $\min\left\{  v_{p}\left(  a\right)
,\ v_{p}\left(  b\right)  \right\}  \neq\infty$. Thus, $\min\left\{
v_{p}\left(  a\right)  ,\ v_{p}\left(  b\right)  \right\}  \in\mathbb{N}$. Set
$k=\min\left\{  v_{p}\left(  a\right)  ,\ v_{p}\left(  b\right)  \right\}  $.
Then, $k\leq v_{p}\left(  a\right)  $ and $k\leq v_{p}\left(  b\right)  $.
From $k\leq v_{p}\left(  a\right)  $, we obtain $v_{p}\left(  a\right)  \geq
k$ and thus $p^{k}\mid a$ (by Lemma \ref{lem.ent.vp.equivalence}, applied to
$n=a$ and $i=k$). Similarly, $p^{k}\mid b$. Thus, $a$ and $b$ are multiples of
$p^{k}$. Hence, their sum $a+b$ is also a multiple of $p^{k}$. In other words,
$p^{k}\mid a+b$. Using Lemma \ref{lem.ent.vp.equivalence}, this in turn
entails $v_{p}\left(  a+b\right)  \geq k=\min\left\{  v_{p}\left(  a\right)
,\ v_{p}\left(  b\right)  \right\}  $. Thus, Theorem \ref{thm.ent.vp.vpab}
\textbf{(b)} is proved.\medskip

\textbf{(c)} This follows from $p^{0}=1\mid1$ and $p^{1}=p\nmid1$.\medskip

\textbf{(d)} This follows from $p^{1}=p\mid p$ and $p^{2}\nmid p$. \medskip

\textbf{(e)} Let $q\neq p$ be a prime. Then, the only positive divisors of $q$
are $1$ and $q$ (since $q$ is a prime). Hence, $p$ is not a positive divisor
of $q$ (since $p\neq1$ and $p\neq q$). Therefore, $p$ is not a divisor of $q$
(since $p$ is positive). In other words, $p\nmid q$. Now, from $p^{0}=1\mid q$
and $p^{1}=p\nmid q$, we obtain $v_{p}\left(  q\right)  =0$. This proves
Theorem \ref{thm.ent.vp.vpab} \textbf{(e)}.
\end{proof}

\begin{corollary}
\label{cor.ent.vp.prodak}Let $p$ be a prime. Then,
\[
v_{p}\left(  a_{1}a_{2}\cdots a_{k}\right)  =v_{p}\left(  a_{1}\right)
+v_{p}\left(  a_{2}\right)  +\cdots+v_{p}\left(  a_{k}\right)
\]
for any $k$ integers $a_{1},a_{2},\ldots,a_{k}$.
\end{corollary}

\begin{proof}
Induct on $k$. The base case uses $v_{p}\left(  1\right)  =0$. The induction
step relies on Theorem \ref{thm.ent.vp.vpab} \textbf{(a)}.
\end{proof}

Note that Theorem \ref{thm.ent.vp.vpab} \textbf{(a)} would fail if $p$ were
allowed to be non-prime. For instance, $v_{4}\left(  2\cdot2\right)  =1$ but
$v_{4}\left(  2\right)  +v_{4}\left(  2\right)  =0+0=0$.

\bigskip

Let us take a closer look at $2$-valuations. The sequence%
\begin{align*}
&  \left(  v_{2}\left(  1\right)  ,\ v_{2}\left(  2\right)  ,\ v_{2}\left(
3\right)  ,\ v_{2}\left(  4\right)  ,\ v_{2}\left(  5\right)  ,\ \ldots\right)
\\
&  =\left(
0,\ 1,\ 0,\ 2,\ 0,\ 1,\ 0,\ 3,\ 0,\ 1,\ 0,\ 2,\ 0,\ 1,\ 0,\ 4,\ \ldots\right)
\end{align*}
is called the
\textbf{\href{https://en.wikipedia.org/wiki/Ruler_function}{\textbf{ruler
sequence}}}, as it resembles the pattern of markings on a ruler (a small
marking at every inch, a slightly larger marking every $2$ inches, an even
larger marking every $4$ inches, and so on). It tends to appear every once in
a while in seemingly unexpected places. Case in point:

\begin{proposition}
\label{prop.rulerfun.hanoi}Let $n\in\mathbb{N}$.

In Section 1.1 (in Lecture 1), we proposed a strategy for solving the Tower of
Hanoi puzzle with $n$ disks. Let $S_{n}$ be this strategy.

Let $k\in\left\{  1,2,\ldots,2^{n}-1\right\}  $. Then, the $k$-th move of the
strategy $S_{n}$ moves the $\left(  v_{2}\left(  k\right)  +1\right)  $-th
smallest disk.
\end{proposition}

Thus, in particular, every odd move (i.e., the $1$-st, the $3$-rd, the $5$-th,
and so on moves) moves the smallest disk (since $v_{2}\left(  k\right)  =0$
when $k$ is odd).

The proof of Proposition \ref{prop.rulerfun.hanoi} relies on the following
lemma about $p$-valuations:

\begin{lemma}
\label{lem.ent.vp.hanoi-lem}Let $p$ be a prime. Let $m\in\mathbb{N}$. Let $k$
be an integer such that $p^{m}\nmid k$. Then, $v_{p}\left(  p^{m}+k\right)
=v_{p}\left(  k\right)  $.
\end{lemma}

\begin{fineprint}
\begin{proof}
[Proof of Lemma \ref{lem.ent.vp.hanoi-lem}.]From $p^{m}\nmid k$, we obtain
$k\neq0$, so that $v_{p}\left(  k\right)  \neq\infty$. In other words,
$v_{p}\left(  k\right)  \in\mathbb{N}$.

Let $i=v_{p}\left(  k\right)  $. Thus, $i\in\mathbb{N}$ (since $v_{p}\left(
k\right)  \in\mathbb{N}$), and the definition of $v_{p}\left(  k\right)  $
shows that $p^{i}\mid k$ and $p^{i+1}\nmid k$.

If we had $m\leq i$, then we would have $p^{m}\mid p^{i}\mid k$, which would
contradict $p^{m}\nmid k$. Thus, we cannot have $m\leq i$. In other words, we
have $i<m$. Thus, $i\leq m-1$ (since $i$ and $m$ are integers), so that
$i+1\leq m$. Therefore, $p^{i+1}\mid p^{m}$.

From the definition of $p$-valuations, it follows easily that $v_{p}\left(
p^{m}\right)  =m$ and $v_{p}\left(  -p^{m}\right)  =m$.

The numbers $p^{m}$ and $k$ are multiples of $p^{i}$ (since $p^{i}\mid
p^{i+1}\mid p^{m}$ and $p^{i}\mid k$). Thus, their sum $p^{m}+k$ is a multiple
of $p^{i}$ as well. In other words, $p^{i}\mid p^{m}+k$.

On the other hand, let us show that $p^{i+1}\nmid p^{m}+k$. Indeed, assume the
contrary. Thus, $p^{i+1}\mid p^{m}+k$.

Therefore, the numbers $p^{m}+k$ and $-p^{m}$ are multiples of $p^{i+1}$
(since $p^{i+1}\mid p^{m}+k$ and $p^{i+1}\mid p^{m}\mid p^{m}\cdot\left(
-1\right)  =-p^{m}$). Hence, their sum $\left(  p^{m}+k\right)  +\left(
-p^{m}\right)  $ is a multiple of $p^{i+1}$ as well. In other words, $k$ is a
multiple of $p^{i+1}$ (since $\left(  p^{m}+k\right)  +\left(  -p^{m}\right)
=k$). But this contradicts $p^{i+1}\nmid k$.

This contradiction shows that our assumption was wrong. Hence, $p^{i+1}\nmid
p^{m}+k$ is proved.

Combining $p^{i}\mid p^{m}+k$ with $p^{i+1}\nmid p^{m}+k$, we see that $i$ is
the largest $j\in\mathbb{N}$ satisfying $p^{j}\mid p^{m}+k$. In other words,
$i=v_{p}\left(  p^{m}+k\right)  $. Hence, $v_{p}\left(  p^{m}+k\right)
=i=v_{p}\left(  k\right)  $. This proves Lemma \ref{lem.ent.vp.hanoi-lem}.
\end{proof}

\begin{proof}
[Proof of Proposition \ref{prop.rulerfun.hanoi}.]We will prove Proposition
\ref{prop.rulerfun.hanoi} by induction on $n$:

\textit{Base case:} If $n=0$, then there exists no $k\in\left\{
1,2,\ldots,2^{n}-1\right\}  $ (since the set $\left\{  1,2,\ldots
,2^{n}-1\right\}  =\left\{  1,2,\ldots,2^{0}-1\right\}  =\left\{
1,2,\ldots,0\right\}  $ is empty in this case). Thus, in this case,
Proposition \ref{prop.rulerfun.hanoi} is vacuously true (i.e., true because it
makes a claim about non-existing objects).

\textit{Induction step:} Let $n$ be a positive integer. Assume (as the
induction hypothesis) that Proposition \ref{prop.rulerfun.hanoi} holds for
$n-1$ instead of $n$. We must now prove that Proposition
\ref{prop.rulerfun.hanoi} holds for $n$ as well.

So let $k\in\left\{  1,2,\ldots,2^{n}-1\right\}  $ be arbitrary. We must prove
that the $k$-th move of the strategy $S_{n}$ moves the $\left(  v_{2}\left(
k\right)  +1\right)  $-th smallest disk.

Lemma \ref{lem.ent.vp.hanoi-lem} (applied to $2$, $n-1$ and $k-2^{n-1}$
instead of $p$, $m$ and $k$) yields%
\[
v_{2}\left(  2^{n-1}+k-2^{n-1}\right)  =v_{2}\left(  k-2^{n-1}\right)  ,
\]
so that%
\begin{equation}
v_{2}\left(  k-2^{n-1}\right)  =v_{2}\left(  \underbrace{2^{n-1}+k-2^{n-1}%
}_{=k}\right)  =v_{2}\left(  k\right)  . \label{pf.prop.rulerfun.hanoi.v2=v2}%
\end{equation}


Recall that the strategy $S_{n}$ was defined recursively: It consists of first
performing the strategy $S_{n-1}$ (but with pegs $2$ and $3$ swapped), then
moving the largest disk (from peg $1$ to peg $3$), and then again performing
the strategy $S_{n-1}$ (but now with pegs $1$ and $2$ swapped). Since strategy
$S_{n-1}$ requires $2^{n-1}-1$ moves in total, we thus conclude that

\begin{enumerate}
\item the first $2^{n-1}-1$ moves of strategy $S_{n}$ are identical with the
corresponding moves of strategy $S_{n-1}$ (except that pegs $2$ and $3$ are swapped);

\item the $2^{n-1}$-th move of strategy $S_{n}$ consists in moving the largest disk;

\item the next $2^{n-1}-1$ moves of strategy $S_{n}$ (that is, the moves
numbered $2^{n-1}+1,\ 2^{n-1}+2,\ \ldots,\ 2^{n}-1$) are identical with the
moves of strategy $S_{n-1}$ (except that pegs $1$ and $2$ are swapped).
\end{enumerate}

Therefore, the $k$-th move of the strategy $S_{n}$

\begin{itemize}
\item moves the same disk as the $k$-th move of $S_{n-1}$ if $k<2^{n-1}$;

\item moves the largest disk if $k=2^{n-1}$;

\item moves the same disk as the $\left(  k-2^{n-1}\right)  $-th move of
$S_{n-1}$ if $k>2^{n-1}$.
\end{itemize}

We thus distinguish between the following three cases:

\textit{Case 1:} We have $k<2^{n-1}$.

\textit{Case 2:} We have $k=2^{n-1}$.

\textit{Case 3:} We have $k>2^{n-1}$.

Let us first consider Case 1. In this case, we have $k<2^{n-1}$. Thus, the
$k$-th move of the strategy $S_{n}$ moves the same disk as the $k$-th move of
$S_{n-1}$ (according to the first of the three bullet points above). But our
induction hypothesis shows that the latter move moves the $\left(
v_{2}\left(  k\right)  +1\right)  $-th smallest disk (since $k\in\left\{
1,2,\ldots,2^{n}-1\right\}  $ and $k<2^{n-1}$ entails $k\in\left\{
1,2,\ldots,2^{n-1}-1\right\}  $). Thus, the former move also moves the
$\left(  v_{2}\left(  k\right)  +1\right)  $-th smallest disk. So the claim we
are trying to prove has been proved in Case 1.

Let us now consider Case 2. In this case, we have $k=2^{n-1}$. Thus, the
$k$-th move of the strategy $S_{n}$ moves the largest disk (according to the
second of the three bullet points above), i.e., the $n$-th smallest disk
(since there are $n$ disks in total, so the largest disk is the $n$-th
smallest). However, we have $k=2^{n-1}$ and thus $v_{2}\left(  k\right)
=v_{2}\left(  2^{n-1}\right)  =n-1$, so that $n=v_{2}\left(  k\right)  +1$.
Thus, the $k$-th move of the strategy $S_{n}$ moves the $\left(  v_{2}\left(
k\right)  +1\right)  $-th smallest disk (because we have shown that it moves
the $n$-th smallest disk). So the claim we are trying to prove has been proved
in Case 2.

Let us finally consider Case 3. In this case, we have $k>2^{n-1}$. Thus, the
$k$-th move of the strategy $S_{n}$ moves the same disk as the $\left(
k-2^{n-1}\right)  $-th move of $S_{n-1}$ (according to the third of the three
bullet points above). But our induction hypothesis (applied to $k-2^{n-1}$
instead of $k$) yields that the latter move moves the $\left(  v_{2}\left(
k-2^{n-1}\right)  +1\right)  $-th smallest disk (since $k\in\left\{
1,2,\ldots,2^{n}-1\right\}  $ and $k>2^{n-1}$ entails $k-2^{n-1}\in\left\{
1,2,\ldots,2^{n-1}-1\right\}  $ quite easily\footnote{Here are the details:
From $k\in\left\{  1,2,\ldots,2^{n}-1\right\}  \subseteq\mathbb{Z}$ and
$k>2^{n-1}$, we see immediately that $k-2^{n-1}$ is a positive integer.
Furthermore, from $k\in\left\{  1,2,\ldots,2^{n}-1\right\}  $, we obtain
$k\leq2^{n}-1=2\cdot2^{n-1}-1=2^{n-1}+2^{n-1}-1$, so that $k-2^{n-1}%
\leq2^{n-1}-1$. Since $k-2^{n-1}$ is a positive integer, this results in
$k-2^{n-1}\in\left\{  1,2,\ldots,2^{n-1}-1\right\}  $.}). Thus, the former
move moves the $\left(  v_{2}\left(  k-2^{n-1}\right)  +1\right)  $-th
smallest disk as well. In view of (\ref{pf.prop.rulerfun.hanoi.v2=v2}), we can
restate this as follows: The former move moves the $\left(  v_{2}\left(
k\right)  +1\right)  $-th smallest disk. So the claim we are trying to prove
has been proved in Case 3.

Thus, we have proved our claim in all three Cases 1, 2 and 3. In other words,
we have shown that the $k$-th move of the strategy $S_{n}$ moves the $\left(
v_{2}\left(  k\right)  +1\right)  $-th smallest disk. Hence, we have proved
that Proposition \ref{prop.rulerfun.hanoi} holds for $n$. This completes the
induction step. Thus, Proposition \ref{prop.rulerfun.hanoi} is proved.
\end{proof}
\end{fineprint}

The ruler sequence also has an appearance in data storage:

\begin{remark}
A
\href{https://en.wikipedia.org/wiki/Backup_rotation_scheme}{\textquotedblleft
Tower of Hanoi\textquotedblright\ backup scheme} is a backup scheme where you
have several backup drives for your system. Every odd day, you back up to the
first drive. Every even day that is not divisible by $4$, you back up to the
second drive. Every day that is divisible by $4$ but not by $8$, you back up
to the third drive. And so on. Thus, on the $k$-th day, you back up to the
$\left(  v_{2}\left(  k\right)  +1\right)  $-th drive. This scheme ensures
that at every point in time, you have both a fresh backup and several levels
of older backups available.

(Of course, I only said \textquotedblleft day\textquotedblright\ for
simplicity; you can use any unit of time instead. Of course, the first drive
will see the largest traffic and therefore will wear out and need replacement.)
\end{remark}

\bigskip

What is the $p$-valuation of a factorial $n!$ ? There turns out to be a nice
formula for this:\footnote{See Definition 3.3.12 and Definition 3.3.2 (in
Lecture 8) for the notations we are using here. The meaning of the infinite
sums will be discussed in the proof of the theorem.}

\begin{theorem}
[de Polignac's formula]\label{thm.ent.vp.polignac}Let $p$ be a prime. Let
$n\in\mathbb{N}$. Then,%
\begin{align*}
v_{p}\left(  n!\right)   &  =\left\lfloor \dfrac{n}{p^{1}}\right\rfloor
+\left\lfloor \dfrac{n}{p^{2}}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}%
}\right\rfloor +\cdots\\
&  =\left(  n//p^{1}\right)  +\left(  n//p^{2}\right)  +\left(  n//p^{3}%
\right)  +\cdots.
\end{align*}

\end{theorem}

\begin{proof}
[Proof sketch.]First, these sums are infinite sums. Why do they make
sense?\footnote{It is trivially easy to concoct an infinite sum that does not
make sense: for instance, $1+1+1+\cdots$, or $\dfrac{1}{1}+\dfrac{1}{2}%
+\dfrac{1}{3}+\cdots$. In general, \textquotedblleft
infinite\textquotedblright\ operations in mathematics do not usually exist
unless their existence has been justified.}

Because we can discard all the addends that are zero, and then only finitely
many nonzero addends remain. For instance, if $p=2$ and $n=13$, then%
\begin{align*}
&  \left\lfloor \dfrac{n}{p^{1}}\right\rfloor +\left\lfloor \dfrac{n}{p^{2}%
}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}}\right\rfloor +\cdots\\
&  =\left\lfloor \dfrac{13}{2^{1}}\right\rfloor +\left\lfloor \dfrac{13}%
{2^{2}}\right\rfloor +\left\lfloor \dfrac{13}{2^{3}}\right\rfloor +\cdots\\
&  =\left\lfloor 6.5\right\rfloor +\left\lfloor 3.25\right\rfloor
+\left\lfloor 1.625\right\rfloor +\left\lfloor 0.8125\right\rfloor
+\left\lfloor 0.40625\right\rfloor +\cdots\\
&  =6+3+1+\underbrace{0+0+0+0+0+\cdots}_{\text{These are zeroes, thus don't
contribute to the sum}}\\
&  =6+3+1=10,
\end{align*}
which is a well-defined (finite) value. More generally, for any prime $p$ and
any $n\in\mathbb{N}$, the sum $\left\lfloor \dfrac{n}{p^{1}}\right\rfloor
+\left\lfloor \dfrac{n}{p^{2}}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}%
}\right\rfloor +\cdots$ has only finitely many nonzero addends (because for
every $i\geq n$, we have $p^{i}\geq p^{n}>n$ and thus $0\leq\dfrac{n}{p^{i}%
}<1$, so that $\left\lfloor \dfrac{n}{p^{i}}\right\rfloor =0$), and thus
becomes a finite sum once we discard all its addends that are zero; but a
finite sum obviously has a well-defined value.

Moreover, for every positive integer $d$, you have $\left\lfloor \dfrac{n}%
{d}\right\rfloor =n//d$ (by Proposition 3.3.13 in Lecture 8). Thus, the two
infinite sums%
\begin{align*}
&  \left\lfloor \dfrac{n}{p^{1}}\right\rfloor +\left\lfloor \dfrac{n}{p^{2}%
}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}}\right\rfloor +\cdots
\ \ \ \ \ \ \ \ \ \ \text{and}\\
&  \left(  n//p^{1}\right)  +\left(  n//p^{2}\right)  +\left(  n//p^{3}%
\right)  +\cdots
\end{align*}
are equal.

It remains to prove that these two sums equal $v_{p}\left(  n!\right)  $. In
other words, we must prove that%
\begin{equation}
v_{p}\left(  n!\right)  =\left\lfloor \dfrac{n}{p^{1}}\right\rfloor
+\left\lfloor \dfrac{n}{p^{2}}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}%
}\right\rfloor +\cdots. \label{pf.thm.ent.vp.polignac.mgoal}%
\end{equation}


We can prove this by induction on $n$:

The \textit{base case} ($n=0$) boils down to $0=0+0+0+\cdots$, which is true.

For the \textit{induction step}, we proceed from $n-1$ to $n$. So we fix a
positive integer $n$, and we assume (as our induction hypothesis) that%
\begin{equation}
v_{p}\left(  \left(  n-1\right)  !\right)  =\left\lfloor \dfrac{n-1}{p^{1}%
}\right\rfloor +\left\lfloor \dfrac{n-1}{p^{2}}\right\rfloor +\left\lfloor
\dfrac{n-1}{p^{3}}\right\rfloor +\cdots, \label{pf.thm.ent.vp.polignac.IH}%
\end{equation}
and we set out to prove that%
\begin{equation}
v_{p}\left(  n!\right)  =\left\lfloor \dfrac{n}{p^{1}}\right\rfloor
+\left\lfloor \dfrac{n}{p^{2}}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}%
}\right\rfloor +\cdots. \label{pf.thm.ent.vp.polignac.IG}%
\end{equation}


We first compare the left hand sides: Let $k=v_{p}\left(  n\right)  $. We know
that $n!=\left(  n-1\right)  !\cdot n$, and therefore%
\begin{align*}
v_{p}\left(  n!\right)   &  =v_{p}\left(  \left(  n-1\right)  !\cdot n\right)
\\
&  =v_{p}\left(  \left(  n-1\right)  !\right)  +\underbrace{v_{p}\left(
n\right)  }_{=k}\ \ \ \ \ \ \ \ \ \ \left(  \text{by Theorem
\ref{thm.ent.vp.vpab} \textbf{(a)}}\right) \\
&  =v_{p}\left(  \left(  n-1\right)  !\right)  +k.
\end{align*}
In other words, the LHS\footnote{The word \textquotedblleft
LHS\textquotedblright\ means \textquotedblleft left hand
side\textquotedblright.
\par
The word \textquotedblleft RHS\textquotedblright\ means \textquotedblleft
right hand side\textquotedblright.} of (\ref{pf.thm.ent.vp.polignac.IG})
equals the LHS of (\ref{pf.thm.ent.vp.polignac.IH}) plus $k$.

Now, we shall show that the RHSs of the two equations differ by $k$ as well.

The main trick is to observe the following:

\begin{statement}
\textit{Claim 1:} Let $d$ be a positive integer. Then:

\textbf{(a)} If $d\nmid n$, then $\left\lfloor \dfrac{n}{d}\right\rfloor
=\left\lfloor \dfrac{n-1}{d}\right\rfloor $.

\textbf{(b)} If $d\mid n$, then $\left\lfloor \dfrac{n}{d}\right\rfloor
=\left\lfloor \dfrac{n-1}{d}\right\rfloor +1$.
\end{statement}

Claim 1 is Corollary 3.3.17 from Lecture 9, so we need not prove it again.

Now, let $k=v_{p}\left(  n\right)  $. Then, for each $i\in\left\{
1,2,\ldots,k\right\}  $, we have $p^{i}\mid p^{k}\mid n$ (since $k=v_{p}%
\left(  n\right)  $) and therefore%
\[
\left\lfloor \dfrac{n}{p^{i}}\right\rfloor =\left\lfloor \dfrac{n-1}{p^{i}%
}\right\rfloor +1\ \ \ \ \ \ \ \ \ \ \left(  \text{by Claim 1 \textbf{(b)}%
}\right)  .
\]
On the other hand, for each $i\in\left\{  k+1,k+2,k+3,\ldots\right\}  $, we
have $p^{i}\nmid n$ (since $i>k=v_{p}\left(  n\right)  $) and thus%
\[
\left\lfloor \dfrac{n}{p^{i}}\right\rfloor =\left\lfloor \dfrac{n-1}{p^{i}%
}\right\rfloor \ \ \ \ \ \ \ \ \ \ \left(  \text{by Claim 1 \textbf{(a)}%
}\right)  .
\]
These two equalities together yield%
\begin{align*}
&  \left\lfloor \dfrac{n}{p^{1}}\right\rfloor +\left\lfloor \dfrac{n}{p^{2}%
}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}}\right\rfloor +\cdots\\
&  =\left(  \left\lfloor \dfrac{n-1}{p^{1}}\right\rfloor +1\right)  +\left(
\left\lfloor \dfrac{n-1}{p^{2}}\right\rfloor +1\right)  +\cdots+\left(
\left\lfloor \dfrac{n-1}{p^{k}}\right\rfloor +1\right) \\
&  \ \ \ \ \ \ \ \ \ \ +\left\lfloor \dfrac{n-1}{p^{k+1}}\right\rfloor
+\left\lfloor \dfrac{n-1}{p^{k+2}}\right\rfloor +\left\lfloor \dfrac
{n-1}{p^{k+3}}\right\rfloor +\cdots\\
&  =\left(  \left\lfloor \dfrac{n-1}{p^{1}}\right\rfloor +\left\lfloor
\dfrac{n-1}{p^{2}}\right\rfloor +\left\lfloor \dfrac{n-1}{p^{3}}\right\rfloor
+\cdots\right)  +k.
\end{align*}
In other words, the RHS of (\ref{pf.thm.ent.vp.polignac.IG}) equals the RHS of
(\ref{pf.thm.ent.vp.polignac.IH}) plus $k$.

But previously, we have shown the same for the LHSs. Thus, the equality
(\ref{pf.thm.ent.vp.polignac.IG}) is just the equality
(\ref{pf.thm.ent.vp.polignac.IH}) with each side increased by $k$. Since
(\ref{pf.thm.ent.vp.polignac.IH}) holds (by the induction hypothesis), it thus
follows that (\ref{pf.thm.ent.vp.polignac.IG}) also holds. In other words,%
\[
v_{p}\left(  n!\right)  =\left\lfloor \dfrac{n}{p^{1}}\right\rfloor
+\left\lfloor \dfrac{n}{p^{2}}\right\rfloor +\left\lfloor \dfrac{n}{p^{3}%
}\right\rfloor +\cdots.
\]
But this completes the induction step, and thus Theorem
\ref{thm.ent.vp.polignac} is proven.

(For another proof of Theorem \ref{thm.ent.vp.polignac}, see \cite[Exercise
2.17.2 \textbf{(c)}]{19s} or \cite[Theorem 5.3.1]{21f5}.)
\end{proof}

Theorem \ref{thm.ent.vp.polignac} is known as \textbf{de Polignac's formula}
or \textbf{Legendre's formula}. Various uses of this formula can be found in
\cite{21f5}.

\begin{noncompile}
\begin{exercise}
How many $0$'s does the number $50!$ end with when written in decimal notation?
\end{exercise}

\begin{proof}
[Solution idea.]TODO: This is to be completed.

This is asking for $v_{10}\left(  50!\right)  $, but unfortunately $10$ is not
a prime, so our formulas above do not apply.

Nevertheless, de Polignac's formula can be applied. Indeed, $10=2\cdot5$, and
the numbers $2$ and $5$ are two distinct primes (hence coprime). This easily
yields that $2^{k}$ and $5^{k}$ are coprime for any $k\in\mathbb{N}$
(exercise). Thus, for any $k\in\mathbb{N}$, we have the equivalence%
\begin{align*}
\left(  10^{k}\mid n!\right)  \  &  \Longleftrightarrow\ \left(  2^{k}\mid
n!\text{ and }5^{k}\mid n!\right) \\
&  \Longleftrightarrow\ \left(  v_{2}\left(  n!\right)  \geq k\text{ and
}v_{5}\left(  n!\right)  \geq k\right)  .
\end{align*}
So the number of $0$'s at the end of $n!$ is $\min\left\{  v_{2}\left(
n!\right)  ,\ v_{5}\left(  n!\right)  \right\}  $ (because this number of
$0$'s is the largest $k\in\mathbb{N}$ such that $10^{k}\mid n!$). Thus, if we
can find $v_{2}\left(  n!\right)  $ and $v_{5}\left(  n!\right)  $, then we
can also find this number of $0$'s.

For $n=50$, we can do this pretty easily using de Polignac's formula:%
\begin{align*}
v_{2}\left(  50!\right)   &  =\left\lfloor \dfrac{50}{2^{1}}\right\rfloor
+\left\lfloor \dfrac{50}{2^{2}}\right\rfloor +\left\lfloor \dfrac{50}{2^{3}%
}\right\rfloor +\cdots\\
&  =25+12+6+3+1+0+0+0+\cdots\\
&  =47
\end{align*}
and%
\begin{align*}
v_{5}\left(  50!\right)   &  =\left\lfloor \dfrac{50}{5^{1}}\right\rfloor
+\left\lfloor \dfrac{50}{5^{2}}\right\rfloor +\left\lfloor \dfrac{50}{5^{3}%
}\right\rfloor +\cdots\\
&  =10+2+0+0+\cdots\\
&  =12,
\end{align*}
so%
\[
\min\left\{  v_{2}\left(  50!\right)  ,\ v_{5}\left(  50!\right)  \right\}
=\min\left\{  47,12\right\}  =12.
\]
So the number $50!$ ends with $12$ zeroes. And indeed,%
\[
50!=\allowbreak30\,\allowbreak414\,093\,201\,\allowbreak
713\,378\,043\,\allowbreak612\,608\,166\,\allowbreak064\,768\,844\,\allowbreak
377\,641\,568\,\allowbreak960\,512\,000\,\allowbreak000\,000\,000\allowbreak.
\]

\end{proof}
\end{noncompile}

\subsubsection{Prime factorization}

We are now ready to prove one of the most important properties of primes: the
fact that every positive integer can be uniquely decomposed into a product of
some primes. For instance,%
\[
200=2\cdot100=2\cdot2\cdot50=2\cdot2\cdot5\cdot10=\underbrace{2\cdot
2\cdot5\cdot2\cdot5}_{\text{a product of primes}}.
\]
The word \textquotedblleft uniquely\textquotedblright\ means here that any two
ways of decomposing a given positive integer $n$ into a product of primes are
equal up to reordering the factors. For example, we can also decompose $200$
as $5\cdot2\cdot2\cdot5\cdot2$, but this is the same product with the factors
in a different order.

Let us state this fact in full generality. First, we introduce a name for
these decompositions:

\begin{definition}
Let $n$ be a positive integer. A \textbf{prime factorization} of $n$ means a
finite list $\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ of primes (not
necessarily distinct) such that%
\[
n=p_{1}p_{2}\cdots p_{k}.
\]

\end{definition}

Thus, $\left(  2,2,5,2,5\right)  $ and $\left(  5,2,2,5,2\right)  $ are prime
factorizations of $200$. Another such is $\left(  2,2,2,5,5\right)  $. There
are more (soon we will perhaps see how many), but all of them contain the
number $2$ thrice and the number $5$ twice (and no other numbers), just as we said.

Let us state this as a general claim:

\begin{theorem}
[Fundamental Theorem of Arithmetic]\label{thm.ent.fta}Let $n$ be a positive
integer. Then: \medskip

\textbf{(a)} There exists a prime factorization of $n$. \medskip

\textbf{(b)} This prime factorization is unique up to reordering its entries.
In other words, if $\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ and $\left(
q_{1},q_{2},\ldots,q_{\ell}\right)  $ are two prime factorizations of $n$,
then $\left(  q_{1},q_{2},\ldots,q_{\ell}\right)  $ can be obtained from
$\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ by reordering the entries.\medskip

\textbf{(c)} Let $\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ be a prime
factorization of $n$. Let $p$ be any prime. Then, the number of times that $p$
appears in the list $\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ (in other
words, the number of $i\in\left\{  1,2,\ldots,k\right\}  $ satisfying
$p_{i}=p$) is $v_{p}\left(  n\right)  $.
\end{theorem}

\begin{proof}
\textbf{(a)} This is Theorem 1.9.6 in Lecture 4. \medskip

\textbf{(c)} By the definition of a prime factorization, we have $n=p_{1}%
p_{2}\cdots p_{k}$. Thus,%
\begin{align}
v_{p}\left(  n\right)   &  =v_{p}\left(  p_{1}p_{2}\cdots p_{k}\right)
\nonumber\\
&  =v_{p}\left(  p_{1}\right)  +v_{p}\left(  p_{2}\right)  +\cdots
+v_{p}\left(  p_{k}\right)  \label{pf.thm.ent.fta.c.1}%
\end{align}
(by Corollary \ref{cor.ent.vp.prodak}).

The right hand side of this equality is a sum of $k$ addends. Each of these
addends has the form $v_{p}\left(  p_{i}\right)  $ for some $i\in\left\{
1,2,\ldots,k\right\}  $. Each such addend $v_{p}\left(  p_{i}\right)  $ equals
$1$ if $p_{i}=p$ (by Theorem \ref{thm.ent.vp.vpab} \textbf{(d)}) and equals
$0$ if $p_{i}\neq p$ (by Theorem \ref{thm.ent.vp.vpab} \textbf{(e)}).

Thus, our sum $v_{p}\left(  p_{1}\right)  +v_{p}\left(  p_{2}\right)
+\cdots+v_{p}\left(  p_{k}\right)  $ has an addend equal to $1$ for each
$i\in\left\{  1,2,\ldots,k\right\}  $ that satisfies $p_{i}=p$, and an addend
equal to $0$ for each $i$ that doesn't.

Obviously, the addends that are equal to $0$ do not affect the sum. Hence, the
sum equals the number of addends equal to $1$. In other words, the sum equals
the number of $i\in\left\{  1,2,\ldots,k\right\}  $ that satisfy $p_{i}=p$.

In view of (\ref{pf.thm.ent.fta.c.1}), we can restate this as follows:
$v_{p}\left(  n\right)  $ equals the number of $i\in\left\{  1,2,\ldots
,k\right\}  $ that satisfy $p_{i}=p$. In other words, $v_{p}\left(  n\right)
$ equals the number of times that $p$ appears in the list $\left(  p_{1}%
,p_{2},\ldots,p_{k}\right)  $. This proves Theorem \ref{thm.ent.fta}
\textbf{(c)}. \medskip

\textbf{(b)} This follows easily from part \textbf{(c)}. Namely:

Let $\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ and $\left(  q_{1}%
,q_{2},\ldots,q_{\ell}\right)  $ be two prime factorizations of $n$. We must
prove that $\left(  q_{1},q_{2},\ldots,q_{\ell}\right)  $ can be obtained from
$\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ by reordering the entries.

Each prime $p$ appears $v_{p}\left(  n\right)  $ times in the list $\left(
p_{1},p_{2},\ldots,p_{k}\right)  $ (by part \textbf{(c)}), and appears
$v_{p}\left(  n\right)  $ times in the list $\left(  q_{1},q_{2}%
,\ldots,q_{\ell}\right)  $ (similarly). Thus, each prime $p$ appears the same
number of times in either list. Since both lists consist of primes, this shows
that the two lists contain the same numbers the same number of times.
Therefore, $\left(  q_{1},q_{2},\ldots,q_{\ell}\right)  $ can be obtained from
$\left(  p_{1},p_{2},\ldots,p_{k}\right)  $ by reordering the entries. This
proves Theorem \ref{thm.ent.fta} \textbf{(b)}.

(We have used the intuitively obvious fact that if two lists of numbers
contain the same numbers the same number of times, then one can be obtained
from the other by reordering. You are free to trust your intuition on this
one; for a formal proof, see \cite[Lemma 2.13.20]{19s}.)
\end{proof}

\bigskip

Theorem \ref{thm.ent.fta} \textbf{(a)} shows that every positive integer $n$
has a prime factorization. Finding this prime factorization is
\href{https://en.wikipedia.org/wiki/Integer_factorization}{a classical hard
computational problem}. (Quite a few encryption standards rely on its hardness.)

\subsection{Least common multiples}

In \S 3.4 (Lecture 9), we have studied greatest common divisors in some
detail. Let me now briefly discuss least common multiples: a kind of
counterpart to greatest common divisors. The greatest common divisor of two
positive integers $a$ and $b$ is usually smaller than both $a$ and $b$; in
contrast, the least common multiple is usually larger than both.

\begin{definition}
Let $a$ and $b$ be two integers.

\textbf{(a)} The \textbf{common multiples} of $a$ and $b$ are the integers
that are divisible by $a$ and simultaneously divisible by $b$.

\textbf{(b)} The \textbf{least common multiple} (aka the \textbf{lowest common
multiple}, or just the \textbf{lcm}) of $a$ and $b$ is defined as follows:

\begin{itemize}
\item If $a$ and $b$ are nonzero, then it is the smallest positive common
multiple of $a$ and $b$.

\item Otherwise, it is $0$.
\end{itemize}

It is denoted by $\operatorname{lcm}\left(  a,b\right)  $.
\end{definition}

Some examples:

\begin{itemize}
\item We have $\operatorname{lcm}\left(  3,4\right)  =12$.

\item We have $\operatorname{lcm}\left(  6,4\right)  =12$.

\item We have $\operatorname{lcm}\left(  6,8\right)  =24$.

\item We have $\operatorname{lcm}\left(  2,4\right)  =4$.

\item We have $\operatorname{lcm}\left(  0,5\right)  =0$.

\item We have $\operatorname{lcm}\left(  -2,3\right)  =6$.
\end{itemize}

Note that the lcm of two positive integers is a fairly well-known concept:
When you bring two fractions (of integers) to their lowest common denominator,
this lowest common denominator is actually the lcm of the denominators of the fractions.

Here are some properties of lcms:

\begin{theorem}
\label{thm.ent.lcm.varia}Let $a$ and $b$ be two integers. Then:

\textbf{(a)} The lcm of $a$ and $b$ exists.

\textbf{(b)} We have $\operatorname{lcm}\left(  a,b\right)  \in\mathbb{N}$.

\textbf{(c)} We have $\operatorname{lcm}\left(  a,b\right)
=\operatorname{lcm}\left(  b,a\right)  $.

\textbf{(d)} We have $a\mid\operatorname{lcm}\left(  a,b\right)  $ and
$b\mid\operatorname{lcm}\left(  a,b\right)  $.

\textbf{(e)} We have $\operatorname{lcm}\left(  -a,b\right)
=\operatorname{lcm}\left(  a,b\right)  $ and $\operatorname{lcm}\left(
a,-b\right)  =\operatorname{lcm}\left(  a,b\right)  $.
\end{theorem}

\begin{proof}
[Proof sketch.]Easy consequences of the definitions. (For part \textbf{(a)},
observe that two nonzero integers $a$ and $b$ have at least one positive
common multiple -- namely, $\left\vert ab\right\vert $.)
\end{proof}

Here is a counterpart to the universal property of the gcd (Theorem 3.4.8 in
Lecture 9):

\begin{theorem}
[universal property of the lcm]\label{thm.ent.lcm.uniprop}Let $a,b,m\in
\mathbb{Z}$. Then, we have the equivalence%
\[
\left(  a\mid m\text{ and }b\mid m\right)  \ \Longleftrightarrow\ \left(
\operatorname{lcm}\left(  a,b\right)  \mid m\right)  .
\]

\end{theorem}

In other words, the common multiples of two integers $a$ and $b$ are precisely
the multiples of $\operatorname{lcm}\left(  a,b\right)  $.

\begin{proof}
[Proof sketch.](See \cite[Theorem 2.11.7]{19s} for a detailed proof.)

$\Longleftarrow:$ If $\operatorname{lcm}\left(  a,b\right)  \mid m$, then
$a\mid m$ (since Theorem \ref{thm.ent.lcm.varia} \textbf{(d)} yields
$a\mid\operatorname{lcm}\left(  a,b\right)  \mid m$) and $b\mid m$
(similarly). Thus, the \textquotedblleft$\Longleftarrow$\textquotedblright%
\ direction of the desired equivalence is proved.

$\Longrightarrow:$ Assume that $a\mid m$ and $b\mid m$. We must show that
$\operatorname{lcm}\left(  a,b\right)  \mid m$.

If one of $a$ and $b$ is $0$, then this is easy (in fact, let's say that
$a=0$; then, $0=a\mid m$, thus $m=0$, and therefore $\operatorname{lcm}\left(
a,b\right)  \mid0=m$). Hence, we need only to consider the case when $a$ and
$b$ are nonzero.

In this case, set $\ell=\operatorname{lcm}\left(  a,b\right)  $. Recall that
$\ell$ is defined as the smallest positive common multiple of $a$ and $b$.
Hence, $\ell$ is a positive integer and is a multiple of $a$ and of $b$. Let
$q$ and $r$ be the quotient and the remainder of the division of $m$ by $\ell
$. Thus,%
\[
q\in\mathbb{Z}\ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ r\in\left\{
0,1,\ldots,\ell-1\right\}  \ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ m=q\ell+r
\]
(by the definition of quotient and remainder). From $r\in\left\{
0,1,\ldots,\ell-1\right\}  $, we obtain $r<\ell$.

From $m=q\ell+r$, we obtain $r=m-q\ell$. Since both $m$ and $\ell$ are
multiples of $a$, we thus conclude that $r$ is a multiple of $a$ as well.
Similarly, $r$ is a multiple of $b$. Thus, $r$ is a common multiple of $a$ and
$b$. But $\ell$ is the smallest positive common multiple of $a$ and $b$. If
$r$ was positive, then $r$ would contradict this minimality (because $r<\ell
$). Hence, $r$ cannot be positive. Since $r\in\left\{  0,1,\ldots
,\ell-1\right\}  $, we conclude that $r$ must be $0$. Hence, $m=q\ell
+\underbrace{r}_{=0}=q\ell$, so that $\ell\mid m$. In other words,
$\operatorname{lcm}\left(  a,b\right)  \mid m$ (since $\ell=\operatorname{lcm}%
\left(  a,b\right)  $). This proves the \textquotedblleft$\Longrightarrow
$\textquotedblright\ direction of the desired equivalence.
\end{proof}

\bigskip

The gcd and the lcm of two integers are connected to each other by the
following formula:

\begin{theorem}
\label{thm.ent.lcm.gcd}Let $a$ and $b$ be two integers. Then,%
\[
\gcd\left(  a,b\right)  \cdot\operatorname{lcm}\left(  a,b\right)  =\left\vert
ab\right\vert .
\]

\end{theorem}

\begin{proof}
[Proof sketch.](See \cite[Theorem 2.11.6]{19s} for a detailed proof.)

First, dispose of the case when $a$ or $b$ is $0$. In the remaining case,
argue that $\dfrac{ab}{\gcd\left(  a,b\right)  }$ is an integer and is a
common multiple of $a$ and $b$. By Theorem \ref{thm.ent.lcm.uniprop}, this
entails that $\operatorname{lcm}\left(  a,b\right)  \mid\dfrac{ab}{\gcd\left(
a,b\right)  }$, so that $\gcd\left(  a,b\right)  \cdot\operatorname{lcm}%
\left(  a,b\right)  \mid ab$. On the other hand, argue (again using Theorem
\ref{thm.ent.lcm.uniprop}) that $\dfrac{ab}{\operatorname{lcm}\left(
a,b\right)  }$ is an integer and divides $\gcd\left(  a,b\right)  $ (because
it divides each of $a$ and $b$). Thus conclude that $ab\mid\gcd\left(
a,b\right)  \cdot\operatorname{lcm}\left(  a,b\right)  $. Now, recall that two
integers $x$ and $y$ that satisfy $x\mid y$ and $y\mid x$ must satisfy
$\left\vert x\right\vert =\left\vert y\right\vert $.
\end{proof}

\bigskip

Both gcds and lcms have easily computable $p$-valuations:

\begin{theorem}
\label{thm.ent.vp.gcd-lcm}Let $p$ be a prime. Let $a$ and $b$ be two integers.
Then,%
\begin{align*}
v_{p}\left(  \gcd\left(  a,b\right)  \right)   &  =\min\left\{  v_{p}\left(
a\right)  ,\ v_{p}\left(  b\right)  \right\}  \ \ \ \ \ \ \ \ \ \ \text{and}\\
v_{p}\left(  \operatorname{lcm}\left(  a,b\right)  \right)   &  =\max\left\{
v_{p}\left(  a\right)  ,\ v_{p}\left(  b\right)  \right\}  .
\end{align*}

\end{theorem}

\begin{proof}
[Proof sketch.]This is a particular case of \cite[Proposition 5.2.15]{19s}.
Anyway, the proof is a nice exercise in using the universal properties of the
gcd and the lcm (and the definition of $p$-valuation), so you should do it yourself.
\end{proof}

Theorem \ref{thm.ent.vp.gcd-lcm} gives an easy way to compute $\gcd\left(
a,b\right)  $ and $\operatorname{lcm}\left(  a,b\right)  $ if you know prime
factorizations of two positive integers $a$ and $b$. For example, knowing that
$18=2\cdot3^{2}$ and $12=2^{2}\cdot3$, we obtain%
\begin{align*}
\gcd\left(  18,\ 12\right)   &  =2\cdot3=6\ \ \ \ \ \ \ \ \ \ \text{and}\\
\operatorname{lcm}\left(  18,\ 12\right)   &  =2^{2}\cdot3^{2}=36.
\end{align*}


If you don't know the prime factorizations of $a$ and $b$, the quickest way to
find $\operatorname{lcm}\left(  a,b\right)  $ is by using the Euclidean
algorithm to find $\gcd\left(  a,b\right)  $ first, and then solving the
equality $\gcd\left(  a,b\right)  \cdot\operatorname{lcm}\left(  a,b\right)
=\left\vert ab\right\vert $ for $\operatorname{lcm}\left(  a,b\right)  $. This
gives\footnote{Here we are assuming that $a$ and $b$ are nonzero. If $a$ or
$b$ is $0$, then $\operatorname{lcm}\left(  a,b\right)  $ is just $0$.}%
\[
\operatorname{lcm}\left(  a,b\right)  =\dfrac{\left\vert ab\right\vert }%
{\gcd\left(  a,b\right)  }=\left\vert \dfrac{a}{\gcd\left(  a,b\right)  }\cdot
b\right\vert .
\]


\bigskip

Gcds and lcms can be defined for multiple numbers (not just for two numbers).
Their properties are mostly analogous to the case of two numbers, with some
exceptions (i.e., the formula $\gcd\left(  a,b\right)  \cdot\operatorname{lcm}%
\left(  a,b\right)  =\left\vert ab\right\vert $ does not generalize to
$\gcd\left(  a,b,c\right)  \cdot\operatorname{lcm}\left(  a,b,c\right)
=\left\vert abc\right\vert $, but rather to $\gcd\left(  a,b,c\right)
\cdot\operatorname{lcm}\left(  bc,ca,ab\right)  =\left\vert abc\right\vert $).
See \cite[\S 2.11]{19s} for more details.

\subsection{Sylvester's $xa+yb$ theorem (or the Chicken McNugget theorem)}

We come to a rather curious (although not overly important) topic in
elementary number theory: the $\mathbb{N}$-linear combinations of two positive integers.

For this entire section, we let $a$ and $b$ be two positive integers.

\begin{definition}
\textbf{(a)} A $\mathbb{Z}$\textbf{-linear combination} (short: $\mathbb{Z}%
$\textbf{-LC}) of $a$ and $b$ will mean a number of the form
\[
xa+yb\ \ \ \ \ \ \ \ \ \ \text{with }x,y\in\mathbb{Z}.
\]
In other words, it means a number of cents that you can pay with $a$-cent
coins and $b$-cent coins if you can get change.

\textbf{(b)} An $\mathbb{N}$\textbf{-linear combination} (short: $\mathbb{N}%
$\textbf{-LC}) of $a$ and $b$ will mean a number of the form
\[
xa+yb\ \ \ \ \ \ \ \ \ \ \text{with }x,y\in\mathbb{N}.
\]
In other words, it means a number of cents that you can pay with $a$-cent
coins and $b$-cent coins without getting change.
\end{definition}

Thus, Proposition 1.9.7 (in Lecture 5) is saying that any integer $n\geq8$ is
an $\mathbb{N}$-LC of $3$ and $5$. Moreover, as we saw just above that
proposition, the numbers $0,\ 3,\ 5,\ 6$ are $\mathbb{N}$-LCs of $3$ and $5$
as well, whereas the numbers $1,\ 2,\ 4,\ 7$ are not. Thus the complete list
of all $\mathbb{N}$-LCs of $3$ and $5$ is
\[
0,\ 3,\ 5,\ 6,\ \underbrace{8,\ 9,\ 10,\ \ldots}_{\text{all integers }n\geq
8}.
\]


This should prompt us to study $\mathbb{N}$-LCs of $a$ and $b$ in the general
case. We shall begin with the $\mathbb{Z}$-LCs, however, since they are much
easier to describe.

Note that the $\mathbb{N}$-LCs of $a$ and $b$ are always $\geq0$ (because if
$x,y\in\mathbb{N}$, then $\underbrace{x}_{\geq0}\underbrace{a}_{>0}%
+\underbrace{y}_{\geq0}\underbrace{b}_{>0}\geq0$), whereas the $\mathbb{Z}%
$-LCs of $a$ and $b$ can have any sign.

Clearly, any $\mathbb{N}$-LC of $a$ and $b$ is a $\mathbb{Z}$-LC of $a$ and
$b$. However, a $\mathbb{Z}$-LC of $a$ and $b$ doesn't have to be an
$\mathbb{N}$-LC of $a$ and $b$, even if it is $\geq0$. For example, $1$ is a
$\mathbb{Z}$-LC of $3$ and $5$ (since $1=2\cdot3+\left(  -1\right)  \cdot5$),
but not an $\mathbb{N}$-LC of $3$ and $5$.

\bigskip

We can easily describe the $\mathbb{Z}$-LCs of $a$ and $b$:

\begin{proposition}
\label{prop.ent.sylv2Z}The $\mathbb{Z}$-LCs of $a$ and $b$ are exactly the
multiples of $\gcd\left(  a,b\right)  $.
\end{proposition}

\begin{fineprint}
\begin{proof}
We must prove the following two claims:

\begin{statement}
\textit{Claim 1:} Any $\mathbb{Z}$-LC of $a$ and $b$ is a multiple of
$\gcd\left(  a,b\right)  $.
\end{statement}

\begin{statement}
\textit{Claim 2:} Any multiple of $\gcd\left(  a,b\right)  $ is a $\mathbb{Z}%
$-LC of $a$ and $b$.
\end{statement}

But both claims are easy:

\begin{proof}
[Proof of Claim 1.]Let $n$ be a $\mathbb{Z}$-LC of $a$ and $b$. We must show
that $n$ is a multiple of $\gcd\left(  a,b\right)  $.

Indeed, $n$ is a $\mathbb{Z}$-LC of $a$ and $b$, and thus has the form
$n=xa+yb$ for some $x,y\in\mathbb{Z}$. Consider these $x,y$. We have
$\gcd\left(  a,b\right)  \mid a\mid xa$ and $\gcd\left(  a,b\right)  \mid
b\mid yb$. In other words, both numbers $xa$ and $yb$ are multiples of
$\gcd\left(  a,b\right)  $. Hence, their sum $xa+yb$ is a multiple of
$\gcd\left(  a,b\right)  $ as well. In other words, $n$ is a multiple of
$\gcd\left(  a,b\right)  $ (since $n=xa+yb$). This proves Claim 1.
\end{proof}

\begin{proof}
[Proof of Claim 2.]Let $n$ be a multiple of $\gcd\left(  a,b\right)  $. We
must prove that $n$ is a $\mathbb{Z}$-LC of $a$ and $b$.

Bezout's theorem (Theorem 3.4.5 in Lecture 9) says that there exist two
integers $x$ and $y$ such that $\gcd\left(  a,b\right)  =xa+yb$. Consider
these $x$ and $y$. However, $n$ is a multiple of $\gcd\left(  a,b\right)  $;
in other words, there exists an integer $c$ such that $n=\gcd\left(
a,b\right)  \cdot c$. Consider this $c$. Now,%
\[
n=\underbrace{\gcd\left(  a,b\right)  }_{=xa+yb}\cdot\,c=\left(  xa+yb\right)
\cdot c=xac+ybc=\left(  cx\right)  a+\left(  cy\right)  b.
\]
This shows that $n$ is a $\mathbb{Z}$-LC of $a$ and $b$ (since $cx$ and $cy$
are integers). This proves Claim 2.
\end{proof}

Combining Claim 1 with Claim 2, we conclude that the $\mathbb{Z}$-LCs of $a$
and $b$ are exactly the multiples of $\gcd\left(  a,b\right)  $. Thus,
Proposition \ref{prop.ent.sylv2Z} is proved.
\end{proof}
\end{fineprint}

\bigskip

Now we move on to the $\mathbb{N}$-LCs. What are they? Can we describe them
any better than by their definition?

Let $g=\gcd\left(  a,b\right)  $. Then, $g$ divides each of $a$ and $b$, so
that the numbers $\dfrac{a}{g}$ and $\dfrac{b}{g}$ are positive integers. We
can simplify our problem by replacing $a$ and $b$ with $\dfrac{a}{g}$ and
$\dfrac{b}{g}$. Clearly, the $\mathbb{N}$-LCs of $a$ and $b$ are just the
$\mathbb{N}$-LCs of $\dfrac{a}{g}$ and $\dfrac{b}{g}$, multiplied by $g$. As
we know (Theorem 3.5.12 in Lecture 10), the two integers $\dfrac{a}{g}$ and
$\dfrac{b}{g}$ are coprime. Thus, understanding the $\mathbb{N}$-LCs of the
original integers $a$ and $b$ is equivalent to understanding the $\mathbb{N}%
$-LCs of the coprime integers $\dfrac{a}{g}$ and $\dfrac{b}{g}$.

Hence, it suffices to solve our problem in the case when $a$ and $b$ are
coprime. In this case, Proposition \ref{prop.ent.sylv2Z} shows that every
integer is a $\mathbb{Z}$-LC of $a$ and $b$ (since every integer is a multiple
of $1=\gcd\left(  a,b\right)  $). The $\mathbb{N}$-LCs are more interesting.
We have already listed the $\mathbb{N}$-LCs of $3$ and $5$ above; let us now
give a somewhat more complicated example: The $\mathbb{N}$-LCs of $5$ and $9$
are%
\[
0,\ 5,\ 9,\ 10,\ 14,\ 15,\ 18,\ 19,\ 20,\ 23,\ 24,\ 25,\ 27,\ 28,\ 29,\ 30,\ \underbrace{32,\ 33,\ 34,\ \ldots
}_{\text{all integers }n\geq32}.
\]
Note that every integer $n\geq32$ is an $\mathbb{N}$-LC of $3$ and $5$. Among
the first $32$ nonnegative integers $0,1,\ldots,31$, exactly half (that is,
$16$) are $\mathbb{N}$-LCs of $5$ and $9$. A similar phenomenon can be seen in
our above example with $3$ and $5$, except that $32$ is replaced by $8$.

This phenomenon generalizes:

\begin{theorem}
[Sylvester's two-coin theorem, or Chicken McNugget theorem]%
\label{thm.ent.sylv2full}Assume that the two positive integers $a$ and $b$ are
coprime. Then: \medskip

\textbf{(a)} Every integer $n>ab-a-b$ is an $\mathbb{N}$-LC of $a$ and $b$.
\medskip

\textbf{(b)} The number $ab-a-b$ is \textbf{not} an $\mathbb{N}$-LC of $a$ and
$b$. \medskip

\textbf{(c)} Among the first $\left(  a-1\right)  \left(  b-1\right)  $
nonnegative integers $0,\ 1,\ \ldots,\ ab-a-b$, exactly half are $\mathbb{N}%
$-LCs of $a$ and $b$. \medskip

\textbf{(d)} Let $n\in\mathbb{Z}$. Then, exactly one of the two numbers $n$
and $ab-a-b-n$ is an $\mathbb{N}$-LC of $a$ and $b$.
\end{theorem}

This theorem was discovered by J. J. Sylvester in 1884, as a side-product of
his work in invariant theory. Its more recent moniker is due to the McDonald's
Chicken McNuggets, which used to be sold in packs of $9$ or $20$, prompting
mathematicians to wonder what numbers of nuggets could be bought.

The theorem stops short of explicitly answering which of the first $\left(
a-1\right)  \left(  b-1\right)  $ nonnegative integers are $\mathbb{N}$-LCs of
$a$ and $b$. There is no \textquotedblleft easy formula\textquotedblright\ for
this answer. But Theorem \ref{thm.ent.sylv2full} \textbf{(a)} gives you all
the information you need to compute all the $\mathbb{N}$-LCs of $a$ and $b$,
since the first $\left(  a-1\right)  \left(  b-1\right)  $ nonnegative
integers can be checked one by one.

The particular case of Theorem \ref{thm.ent.sylv2full} \textbf{(a)} where
$a=p$ and $b=p+1$ was Exercise 4 on homework set \#3. \medskip

Before we prove Theorem \ref{thm.ent.sylv2full}, we show a basic lemma:

\begin{lemma}
\label{lem.ent.sylv2lim}Assume that the two positive integers $a$ and $b$ are
coprime. Let $n\in\mathbb{Z}$. Then, there exist two integers $u$ and $v$ such
that $0\leq u\leq b-1$ and $ua+vb=n$.
\end{lemma}

\begin{fineprint}
\begin{proof}
[Proof of Lemma \ref{lem.ent.sylv2lim}.]Bezout's theorem (Theorem 3.4.5 in
Lecture 9) says that there exist two integers $x$ and $y$ such that
$\gcd\left(  a,b\right)  =xa+yb$. Consider these $x$ and $y$. Thus,
$xa+yb=\gcd\left(  a,b\right)  =1$ (since $a$ and $b$ are coprime).

Recall that $b$ is a positive integer. Thus, division with remainder by $b$ is
well-defined (see Definition 3.3.2 in Lecture 8 for the terminology).

Let $q=\left(  nx\right)  //b$ and $r=\left(  nx\right)  \%b$. In other words,
let $q$ and $r$ be the quotient and the remainder of the division of $nx$ by
$b$. By the definition of quotient and remainder, we thus have%
\[
q\in\mathbb{Z}\ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ r\in\left\{
0,1,\ldots,b-1\right\}  \ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ nx=qb+r.
\]


From $r\in\left\{  0,1,\ldots,b-1\right\}  $, we see that $r$ is an integer
satisfying $0\leq r\leq b-1$.

On the other hand, $nxa+nyb=n\underbrace{\left(  xa+yb\right)  }_{=1}=n$, so
that%
\begin{align*}
n  &  =\underbrace{nx}_{=qb+r}a+nyb=\left(  qb+r\right)  a+nyb\\
&  =qba+ra+nyb=ra+\underbrace{qba+nyb}_{=\left(  qa+ny\right)  b}=ra+\left(
qa+ny\right)  b.
\end{align*}
In other words, $ra+\left(  qa+ny\right)  b=n$.

Altogether, we now know that $r$ and $qa+ny$ are two integers satisfying
$0\leq r\leq b-1$ and $ra+\left(  qa+ny\right)  b=n$. Thus, there exist two
integers $u$ and $v$ such that $0\leq u\leq b-1$ and $ua+vb=n$ (namely, $u=r$
and $v=qa+ny$). This proves Lemma \ref{lem.ent.sylv2lim}.
\end{proof}

\begin{proof}
[Proof of Theorem \ref{thm.ent.sylv2full}.]We shall first prove part
\textbf{(b)} and then part \textbf{(d)}. The other two parts will follow quite
easily from these. \medskip

\textbf{(b)} Assume the contrary. Thus, $ab-a-b$ is an $\mathbb{N}$-LC of $a$
and $b$. In other words, there exist integers $x$ and $y$ such that
$ab-a-b=xa+yb$. Consider these $x$ and $y$.

From $ab-a-b=xa+yb$, we obtain $ab=xa+yb+a+b=\left(  x+1\right)  a+\left(
y+1\right)  b=a\left(  x+1\right)  +b\left(  y+1\right)  $. Hence,%
\[
b\left(  y+1\right)  =ab-a\left(  x+1\right)  =a\cdot\underbrace{\left(
b-\left(  x+1\right)  \right)  }_{\text{an integer}}.
\]
This shows that $a\mid b\left(  y+1\right)  $. Thus, the coprime removal
theorem (Theorem 3.5.6 in Lecture 10) yields that $a\mid y+1$ (since $a$ is
coprime to $b$). Therefore, $\dfrac{y+1}{a}$ is an integer (since $a\neq0$).
Since $\underbrace{y}_{\geq0}+\,1\geq1>0$ and $a>0$, this integer $\dfrac
{y+1}{a}$ is furthermore positive, and thus is $\geq1$. In other words,
$y+1\geq a$. Hence, $y\geq a-1$. Now,%
\[
ab-a-b=\underbrace{x}_{\geq0}a+\underbrace{y}_{\geq a-1}b\geq0a+\left(
a-1\right)  b=ab-b.
\]
Subtracting $ab-a-b$ from both sides of this inequality, we obtain $0\geq a$,
which contradicts the positivity of $a$. This contradiction shows that our
assumption was false. Thus, Theorem \ref{thm.ent.sylv2full} \textbf{(b)} is
proved. \medskip

\textbf{(d)} Let $m=ab-a-b-n$. Hence, $n+m=ab-a-b$. Thus, $n+m$ is not an
$\mathbb{N}$-LC of $a$ and $b$ (since Theorem \ref{thm.ent.sylv2full}
\textbf{(b)} shows that $ab-a-b$ is not an $\mathbb{N}$-LC of $a$ and $b$).

We shall now prove the following two claims:

\begin{statement}
\textit{Claim 1:} At \textbf{least} one of the two numbers $n$ and $m$ is an
$\mathbb{N}$-LC of $a$ and $b$.
\end{statement}

\begin{statement}
\textit{Claim 2:} At \textbf{most} one of the two numbers $n$ and $m$ is an
$\mathbb{N}$-LC of $a$ and $b$.
\end{statement}

\begin{proof}
[Proof of Claim 1.]Lemma \ref{lem.ent.sylv2lim} shows that there exist two
integers $u$ and $v$ such that $0\leq u\leq b-1$ and $ua+vb=n$. Consider these
$u$ and $v$. Now,%
\begin{align}
\left(  b-1-u\right)  a+\left(  -v-1\right)  b  &  =ba-a-ua-vb-b\nonumber\\
&  =\underbrace{ba}_{=ab}-a-b-\underbrace{\left(  ua+vb\right)  }%
_{=n}\nonumber\\
&  =ab-a-b-n=m \label{pf.thm.ent.sylv2full.d.1}%
\end{align}
(by the definition of $m$). We are in one of the following two cases:

\textit{Case 1:} We have $v\geq0$.

\textit{Case 2:} We have $v<0$.

Let us first consider Case 1. In this case, we have $v\geq0$. Thus,
$v\in\mathbb{N}$. Also, $u\in\mathbb{N}$ (since $0\leq u$). Recall that
$ua+vb=n$, so that $n=\underbrace{u}_{\in\mathbb{N}}a+\underbrace{v}%
_{\in\mathbb{N}}b$. This shows that $n$ is an $\mathbb{N}$-LC of $a$ and $b$.
Thus, at least one of the two numbers $n$ and $m$ is an $\mathbb{N}$-LC of $a$
and $b$. So we have proved Claim 1 in Case 1.

Let us next consider Case 2. In this case, we have $v<0$. Hence, $-v>0$, so
that $-v\geq1$ (since $-v$ is an integer) and therefore $-v-1\geq0$. Thus,
$-v-1\in\mathbb{N}$. Moreover, from $u\leq b-1$, we obtain $b-1-u\geq0$, so
that $b-1-u\in\mathbb{N}$. However, (\ref{pf.thm.ent.sylv2full.d.1}) yields%
\[
m=\underbrace{\left(  b-1-u\right)  }_{\in\mathbb{N}}a+\underbrace{\left(
-v-1\right)  }_{\in\mathbb{N}}b.
\]
This shows that $m$ is an $\mathbb{N}$-LC of $a$ and $b$. Thus, at least one
of the two numbers $n$ and $m$ is an $\mathbb{N}$-LC of $a$ and $b$. So we
have proved Claim 1 in Case 2.

Thus, Claim 1 holds in each of Cases 1 and 2. The proof of Claim 1 is
therefore complete.
\end{proof}

\begin{proof}
[Proof of Claim 2.]Assume the contrary. Thus, both numbers $n$ and $m$ are
$\mathbb{N}$-LCs of $a$ and $b$. Therefore, we can write $n$ as $n=xa+yb$ for
some $x,y\in\mathbb{N}$ (since $n$ is an $\mathbb{N}$-LC of $a$ and $b$).
Furthermore, we can write $m$ as $m=za+wb$ for some $z,w\in\mathbb{N}$ (since
$m$ is an $\mathbb{N}$-LC of $a$ and $b$). Consider these $x,y,z,w$. Now,
adding the equalities $n=xa+yb$ and $m=za+wb$ together, we obtain
\[
n+m=\left(  xa+yb\right)  +\left(  za+wb\right)  =\underbrace{\left(
x+z\right)  }_{\in\mathbb{N}}a+\underbrace{\left(  y+w\right)  }%
_{\in\mathbb{N}}b.
\]
This shows that $n+m$ is an $\mathbb{N}$-LC of $a$ and $b$. This contradicts
the fact that $n+m$ is not an $\mathbb{N}$-LC of $a$ and $b$. This
contradiction shows that our assumption was wrong. Hence, Claim 2 is proved.
\end{proof}

Combining Claim 1 with Claim 2, we see that exactly one of the two numbers $n$
and $m$ is an $\mathbb{N}$-LC of $a$ and $b$. In other words, exactly one of
the two numbers $n$ and $ab-a-b-n$ is an $\mathbb{N}$-LC of $a$ and $b$ (since
$m=ab-a-b-n$). This proves Theorem \ref{thm.ent.sylv2full} \textbf{(d)}.
\medskip

\textbf{(a)} Let $n>ab-a-b$. Then, the integer $ab-a-b-n$ is negative, and
thus cannot be an $\mathbb{N}$-LC of $a$ and $b$ (since any $\mathbb{N}$-LC of
$a$ and $b$ is $\geq0$). However, Theorem \ref{thm.ent.sylv2full} \textbf{(d)}
yields that exactly one of the two numbers $n$ and $ab-a-b-n$ is an
$\mathbb{N}$-LC of $a$ and $b$. Since $ab-a-b-n$ cannot be an $\mathbb{N}$-LC
of $a$ and $b$, we thus conclude that $n$ is an $\mathbb{N}$-LC of $a$ and
$b$. This proves Theorem \ref{thm.ent.sylv2full} \textbf{(a)}. \medskip

\textbf{(c)} Consider the following table of integers:%
\[%
\begin{tabular}
[c]{|c|c|c|c|c|c|}\hline
$0$ & $1$ & $2$ & $\cdots\cdots\cdots$ & $ab-a-b-1$ & $ab-a-b$\\\hline
$ab-a-b$ & $ab-a-b-1$ & $ab-a-b-2$ & $\cdots\cdots\cdots$ & $1$ & $0$\\\hline
\end{tabular}
\]
(whose first row is listing the numbers $0,1,2,\ldots,ab-a-b$ in increasing
order, while the second row is listing the same numbers in decreasing order).
This table has $ab-a-b+1=\left(  a-1\right)  \left(  b-1\right)  $ many columns.

Each column of this table contains the numbers $n$ and $ab-a-b-n$ for some
$n\in\left\{  0,1,\ldots,ab-a-b\right\}  $. Thus, each column of this table
contains exactly one $\mathbb{N}$-LC of $a$ and $b$ (by Theorem
\ref{thm.ent.sylv2full} \textbf{(d)}). Hence, in total, exactly $\left(
a-1\right)  \left(  b-1\right)  $ entries of our table are $\mathbb{N}$-LCs of
$a$ and $b$ (since our table has $\left(  a-1\right)  \left(  b-1\right)  $
many columns). Since our table contains each element of the set $\left\{
0,1,\ldots,ab-a-b\right\}  $ exactly twice, this entails that exactly
$\dfrac{\left(  a-1\right)  \left(  b-1\right)  }{2}$ elements of this set are
$\mathbb{N}$-LCs of $a$ and $b$. In other words, among the elements of the set
$\left\{  0,1,\ldots,ab-a-b\right\}  $, exactly half are $\mathbb{N}$-LCs of
$a$ and $b$. But this is precisely the claim of Theorem
\ref{thm.ent.sylv2full} \textbf{(c)}. Thus, Theorem \ref{thm.ent.sylv2full}
\textbf{(c)} is proved.
\end{proof}
\end{fineprint}

Theorem \ref{thm.ent.sylv2full} is one of the deepest results we will see in
this course, but it is only the beginning of a theory! See
\href{https://en.wikipedia.org/wiki/Coin_problem}{the Wikipedia page for
\textquotedblleft Coin problem\textquotedblright} for more general (and
trickier) questions, such as describing the $\mathbb{N}$-LCs of three integers
$a,b,c$. See also
\href{https://www.math.miami.edu/~armstrong/Talks/RCC_FPSAC_17.pdf}{the slides
of Drew Armstrong's talk at FPSAC 2017} for deep connections to algebraic
combinatorics (and a visual proof different from ours).

\begin{thebibliography}{9999}                                                                                             %


\bibitem[19s]{19s}Darij Grinberg, \textit{Introduction to Modern Algebra (UMN
Spring 2019 Math 4281 notes)}, 29 June 2019.\newline\url{http://www.cip.ifi.lmu.de/~grinberg/t/19s/notes.pdf}

\bibitem[21f5]{21f5}Darij Grinberg, \textit{Math 235 Fall 2021, Worksheet 5:
}$\mathit{p}$\textit{-valuations}, 29 December 2021.\newline\url{https://www.cip.ifi.lmu.de/~grinberg/t/21f/lec5.pdf}
\end{thebibliography}


\end{document}