\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{hyperref}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{needspace}
\usepackage{tabls}
\usepackage{wasysym}
\usepackage{easytable}
\usepackage{ytableau}
%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{LastRevised=Wednesday, October 11, 2023 10:45:21}
%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}
\newcounter{exer}
\newcounter{exera}
\numberwithin{exer}{subsection}
\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}{\medskip \begin{small}}{\end{small} \medskip}
\iffalse
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{question}[1][Question]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{warning}[1][Warning]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{teachingnote}[1][Teaching note]{\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}
\setlength\tablinesep{3pt}
\setlength\arraylinesep{3pt}
\setlength\extrarulesep{3pt}
\voffset=0cm
\hoffset=-0.7cm
\setlength\textheight{22.5cm}
\setlength\textwidth{15.5cm}
\newcommand\arxiv[1]{\href{http://www.arxiv.org/abs/#1}{\texttt{arXiv:#1}}}
\newenvironment{verlong}{}{}
\newenvironment{vershort}{}{}
\newenvironment{noncompile}{}{}
\newenvironment{teachingnote}{}{}
\excludecomment{verlong}
\includecomment{vershort}
\excludecomment{noncompile}
\excludecomment{teachingnote}
\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{\id}{\operatorname{id}}
\newcommand{\lcm}{\operatorname{lcm}}
\newcommand{\rev}{\operatorname{rev}}
\newcommand{\powset}[2][]{\ifthenelse{\equal{#2}{}}{\mathcal{P}\left(#1\right)}{\mathcal{P}_{#1}\left(#2\right)}}
\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{\lf}[2]{#1^{\underline{#2}}}
\newcommand{\underbrack}[2]{\underbrace{#1}_{\substack{#2}}}
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}
\newcommand{\are}{\ar@{-}}
\newcommand{\nnn}{\nonumber\\}
\newcommand{\sslash}{\mathbin{/\mkern-6mu/}}
\newcommand{\numboxed}[2]{\underbrace{\boxed{#1}}_{\text{box } #2}}
\newcommand{\ig}[2]{\includegraphics[scale=#1]{#2.png}}
\iffalse
\NOEXPAND{\today}{\today}
\NOEXPAND{\sslash}{\sslash}
\NOEXPAND{\numboxed}[2]{\numboxed}
\fi
\ihead{Math 235 Fall 2023, Worksheet 2, version \today}
\ohead{page \thepage}
\cfoot{Darij Grinberg}
\begin{document}
\setcounter{section}{1}

\section{Math 235 Fall 2023, Worksheet 2: Modular arithmetic}

Modular arithmetic was introduced by Gauss, and has since become one of the
most fundamental tools in number theory (and, via its generalization to
arbitrary ideals in rings, in abstract algebra). We will state its
foundational results without proof, as the proofs are both easy and easily
found in the literature.

The symbol $\mathbb{N}$ will denote the set $\left\{  0,1,2,\ldots\right\}  $.

\subsection{The definition of congruence}

The fundamental notion of modular arithmetic is \emph{congruence modulo }$n$:

\begin{definition}
\label{def.ent.cong}Let $n,a,b\in\mathbb{Z}$. We say that $a$\emph{ is
congruent to }$b$\emph{ modulo }$n$ if and only if $n\mid a-b$. We shall use
the notation \textquotedblleft$a\equiv b\operatorname{mod}n$\textquotedblright%
\ for \textquotedblleft$a$ is congruent to $b$ modulo $n$\textquotedblright.

We furthermore shall use the notation \textquotedblleft$a\not \equiv
b\operatorname{mod}n$\textquotedblright\ for \textquotedblleft$a$ is not
congruent to $b$ modulo $n$\textquotedblright.
\end{definition}

For example:

\begin{itemize}
\item We have $3\equiv7\operatorname{mod}2$, since $2\mid3-7=-4$.

\item We have $3\not \equiv 6\operatorname{mod}2$, since $2\nmid3-6=-3$.

\item Two integers $a$ and $b$ satisfy $a\equiv b\operatorname{mod}0$ if and
only if $a=b$. (Indeed, $a\equiv b\operatorname{mod}0$ is defined to mean
$0\mid a-b$, but the latter divisibility happens only when $a-b=0$, which is
tantamount to saying $a=b$.)

\item We have $a\equiv b\operatorname{mod}1$ for any two integers $a$ and $b$.
\end{itemize}

The relation \textquotedblleft$a\equiv b\operatorname{mod}n$\textquotedblright%
, as a relation between the two integers $a$ and $b$ (for fixed $n$), is
called a \emph{congruence modulo }$n$.

\subsection{Basic properties of congruence}

Here are some basic rules for dealing with congruences (prove them yourself,
or see \cite[\S 2.3]{19s} for the proofs):

\begin{proposition}
\label{prop.ent.mod.0}Let $n\in\mathbb{Z}$ and $a\in\mathbb{Z}$. Then,
$a\equiv0\operatorname{mod}n$ if and only if $n\mid a$. (Thus, in particular,
$n\equiv0\operatorname{mod}n$ always holds.)
\end{proposition}

\begin{proposition}
\label{prop.ent.mod.a+nd}Let $a,b,n\in\mathbb{Z}$. Then, $a\equiv
b\operatorname{mod}n$ if and only if there exists some $d\in\mathbb{Z}$ such
that $b=a+nd$.
\end{proposition}

\begin{proposition}
\label{prop.ent.mod.diff}Let $a,b,c,n\in\mathbb{Z}$. Then, $a-b\equiv
c\operatorname{mod}n$ if and only if $a\equiv b+c\operatorname{mod}n$.
\end{proposition}

\begin{proposition}
\label{prop.ent.mod.basics}Let $n\in\mathbb{Z}$.

\begin{enumerate}
\item[\textbf{(a)}] We have $a\equiv a\operatorname{mod}n$ for every
$a\in\mathbb{Z}$. (This is called the \emph{reflexivity of congruence}.)

\item[\textbf{(b)}] If $a,b,c\in\mathbb{Z}$ satisfy $a\equiv
b\operatorname{mod}n$ and $b\equiv c\operatorname{mod}n$, then $a\equiv
c\operatorname{mod}n$. (This is called the \emph{transitivity of congruence}.)

\item[\textbf{(c)}] If $a,b\in\mathbb{Z}$ satisfy $a\equiv b\operatorname{mod}%
n$, then $b\equiv a\operatorname{mod}n$. (This is called the \emph{symmetry of
congruence}.)

\item[\textbf{(d)}] If $a_{1},a_{2},b_{1},b_{2}\in\mathbb{Z}$ satisfy
$a_{1}\equiv b_{1}\operatorname{mod}n$ and $a_{2}\equiv b_{2}%
\operatorname{mod}n$, then%
\begin{align}
a_{1}+a_{2}  &  \equiv b_{1}+b_{2}\operatorname{mod}%
n;\label{eq.prop.ent.mod.basics.d.1}\\
a_{1}-a_{2}  &  \equiv b_{1}-b_{2}\operatorname{mod}%
n;\label{eq.prop.ent.mod.basics.d.2}\\
a_{1}a_{2}  &  \equiv b_{1}b_{2}\operatorname{mod}n.
\label{eq.prop.ent.mod.basics.d.3}%
\end{align}


\item[\textbf{(e)}] Let $m\in\mathbb{Z}$ be such that $m\mid n$. If
$a,b\in\mathbb{Z}$ satisfy $a\equiv b\operatorname{mod}n$, then $a\equiv
b\operatorname{mod}m$.
\end{enumerate}
\end{proposition}

\begin{proposition}
\label{prop.ent.mod.k-power}Let $n,a,b\in\mathbb{Z}$ be such that $a\equiv
b\operatorname{mod}n$. Then, $a^{k}\equiv b^{k}\operatorname{mod}n$ for each
$k\in\mathbb{N}$.
\end{proposition}

Proposition \ref{prop.ent.mod.basics} \textbf{(b)} allows us to chain
congruences together like equalities (as long as they all are congruences
modulo the same $n$). Proposition \ref{prop.ent.mod.basics} \textbf{(c)}
allows us to turn them around. Combined with Proposition
\ref{prop.ent.mod.basics} \textbf{(a)} (which says that any equality is a
congruence), these two facts reveal that congruence modulo $n$ (for fixed
$n\in\mathbb{Z}$) is an equivalence relation. We will often use this
implicitly when we chain congruences (modulo the same $n$) together. For
example, we will write%
\[
a\equiv b\equiv c\equiv d\operatorname{mod}n
\]
to mean that $a\equiv b\operatorname{mod}n$ and $b\equiv c\operatorname{mod}n$
and $c\equiv d\operatorname{mod}n$. Such a chain of congruences then implies
that any of the four numbers $a,b,c,d$ is congruent to any other modulo $n$
(since congruence modulo $n$ is an equivalence relation). Equality signs ($=$)
can also appear in such a chain, since Proposition \ref{prop.ent.mod.basics}
\textbf{(a)} says that any equality is a congruence.

Proposition \ref{prop.ent.mod.basics} \textbf{(d)} allows us to add, subtract
and multiply (but not divide) two congruences together. Finally, Proposition
\ref{prop.ent.mod.k-power} allows us to take congruences to $k$-th powers
whenever $k\in\mathbb{N}$.

\subsection{A first application}

Before stating any more general properties, let us see how the ones above can
be used:

\begin{exercise}
\label{exe.mod.e1} Let $n\in\mathbb{N}$. Show that $7\mid3^{2n+1}+2^{n+2}$.
\end{exercise}

\begin{proof}
[Solution to Exercise \ref{exe.mod.e1}.]We have $3^{2}=9\equiv
2\operatorname{mod}7$. Thus, Proposition \ref{prop.ent.mod.k-power} (applied
to $7$, $3^{2}$, $2$ and $n$ instead of $n$, $a$, $b$ and $k$) yields $\left(
3^{2}\right)  ^{n}\equiv2^{n}\operatorname{mod}7$. Multiplying this
congruence\footnote{i.e., applying (\ref{eq.prop.ent.mod.basics.d.3})} by the
obvious congruence $3\equiv3\operatorname{mod}7$, we obtain $\left(
3^{2}\right)  ^{n}\cdot3\equiv2^{n}\cdot3\operatorname{mod}7$. Thus,
$3^{2n+1}=\left(  3^{2}\right)  ^{n}\cdot3\equiv2^{n}\cdot3\operatorname{mod}%
7$. On the other hand, $2^{n+2}=2^{n}\cdot2^{2}=2^{n}\cdot4$, so that
$2^{n+2}\equiv2^{n}\cdot4\operatorname{mod}7$ (since any equality is a congruence).

Now, adding the two congruences\footnote{i.e., applying
(\ref{eq.prop.ent.mod.basics.d.1})} $3^{2n+1}\equiv2^{n}\cdot
3\operatorname{mod}7$ and $2^{n+2}\equiv2^{n}\cdot4\operatorname{mod}7$, we
obtain%
\[
3^{2n+1}+2^{n+2}\equiv2^{n}\cdot3+2^{n}\cdot4=2^{n}\cdot\underbrace{\left(
3+4\right)  }_{=7}=2^{n}\cdot7\equiv0\operatorname{mod}7
\]
(since $2^{n}\cdot7$ is clearly divisible by $7$). In other words,
$7\mid3^{2n+1}+2^{n+2}$. This solves Exercise \ref{exe.mod.e1}.
\end{proof}

\subsection{The substitution principle}

Let us state some further general properties of congruences.

We know from Proposition \ref{prop.ent.mod.basics} \textbf{(d)} that we can
add or subtract any two congruences. Thus, by induction, we can add or
multiply any finite number of congruences together:

\begin{proposition}
\label{prop.ent.mod.k-sum}Let $n$ be an integer. Let $S$ be a finite set. For
each $s\in S$, let $a_{s}$ and $b_{s}$ be two integers. Assume that%
\begin{equation}
a_{s}\equiv b_{s}\operatorname{mod}n\ \ \ \ \ \ \ \ \ \ \text{for each }s\in
S. \label{eq.exe.ent.mod.k-sum.ass}%
\end{equation}
Then,%
\[
\sum_{s\in S}a_{s}\equiv\sum_{s\in S}b_{s}\operatorname{mod}%
n\ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ \prod_{s\in S}a_{s}%
\equiv\prod_{s\in S}b_{s}\operatorname{mod}n.
\]

\end{proposition}

As a consequence of all the properties stated above, we can \emph{substitute}
numbers inside a congruence. That is, the following principle holds:

\begin{statement}
\textit{Substitution principle for congruences:} Let $a,b,n$ be three integers
satisfying $a\equiv b\operatorname{mod}n$. Let $E$ be a \textquotedblleft
reasonable\textquotedblright\ expression that contains $a$ in it. If we
substitute all of the $a$'s in $E$ by $b$'s\footnote{More generally, we can
replace \textbf{some} of the $a$'s in $E$ by $b$'s. For example, we can
replace the first two $a$'s in $a^{3}+a^{2}+a$ by $b$'s, obtaining
$b^{3}+b^{2}+a$.}, then the resulting expression $F$ will satisfy $E\equiv
F\operatorname{mod}n$.
\end{statement}

For example, if $a,b,n$ are three integers satisfying $a\equiv
b\operatorname{mod}n$, then $a^{3}+7a^{2}-5\equiv b^{3}+7b^{2}%
-5\operatorname{mod}n$. Informally speaking, this is because the congruence
$a\equiv b\operatorname{mod}n$ allows us to substitute $b$ for $a$ in
$a^{3}+7a^{2}-5$ (in the same way as $a=b$ would lead us to $a^{3}%
+7a^{2}-5=b^{3}+7b^{2}-5$). Formally speaking, this is a consequence of
Proposition \ref{prop.ent.mod.basics} and Proposition
\ref{prop.ent.mod.k-power} (see \cite[Example 3.2.13]{20f} and \cite[\S 2.5]%
{19s} for details).

When I stated the substitution principle for congruences, I did not specify
what \textquotedblleft reasonable\textquotedblright\ means. And indeed, there
are some limits to the principle: While it is true that $a\equiv
b\operatorname{mod}n$ implies $a^{2}\equiv b^{2}\operatorname{mod}n$, it is
\textbf{not} true that $a\equiv b\operatorname{mod}n$ implies $2^{a}%
\equiv2^{b}\operatorname{mod}n$ (counterexample: $n=2$, $a=0$ and $b=2$).
Thus, while we can substitute integers in the base of a power (because of
Proposition \ref{prop.ent.mod.k-power}), we \textbf{cannot} substitute
integers in the exponent of a power (since there is no analogue of Proposition
\ref{prop.ent.mod.k-power} that would say that $k^{a}\equiv k^{b}%
\operatorname{mod}n$ for each $k\in\mathbb{N}$). Likewise, substitution is not
allowed in fractions or more complicated functions. It is best to read
\textquotedblleft reasonable\textquotedblright\ as \textquotedblleft
polynomial\textquotedblright\ in the substitution principle (with the caveat
that all coefficients of the polynomial must be integers, and that the
exponents are not to be changed).

Using the substitution principle, we can rewrite our above solution to
Exercise \ref{exe.mod.e1} to make it much shorter:

\begin{proof}
[Solution to Exercise \ref{exe.mod.e1} (shortened version).]We have
$3^{2}=9\equiv2\operatorname{mod}7$. Thus, $3^{2n+1}=\left(  \underbrace{3^{2}%
}_{\equiv2\operatorname{mod}7}\right)  ^{n}\cdot3\equiv2^{n}\cdot
3\operatorname{mod}7$ (here, we have used the substitution principle to
substitute $2$ for $3^{2}$). Hence, (again using the substitution principle)
we have%
\[
\underbrace{3^{2n+1}}_{\equiv2^{n}\cdot3\operatorname{mod}7}%
+\underbrace{2^{n+2}}_{=2^{n}\cdot2^{2}=2^{n}\cdot4}\equiv2^{n}\cdot
3+2^{n}\cdot4=2^{n}\cdot\underbrace{\left(  3+4\right)  }_{=7}=2^{n}%
\cdot7\equiv0\operatorname{mod}7
\]
(since $2^{n}\cdot7$ is clearly divisible by $7$). In other words,
$7\mid3^{2n+1}+2^{n+2}$. This solves Exercise \ref{exe.mod.e1}.
\end{proof}

\subsection{Congruence vs. remainders}

When $n$ is a positive integer, congruences modulo $n$ are closely related to
remainders upon division by $n$. We recall how the latter are defined (and
introduce some notation for them):

\begin{definition}
\label{def.ent.quorem}Let $n$ be a positive integer. Let $u\in\mathbb{Z}$.
Then, there exists a unique pair $\left(  q,r\right)  \in\mathbb{Z}%
\times\left\{  0,1,\ldots,n-1\right\}  $ such that $u=qn+r$. The entries $q$
and $n$ of this pair are denoted by $u//n$ and $u\%n$, and are called the
\emph{quotient} and the \emph{remainder} of the division of $u$ by $n$.
\end{definition}

For instance, $17//5=3$ and $17\%5=2$.

Here are some basic properties of quotients and remainders (see \cite[\S 2.6]%
{19s} for the proofs of the first two propositions):

\begin{proposition}
\label{prop.ent.quorem.props}Let $n$ be a positive integer. Let $u\in
\mathbb{Z}$.

\begin{enumerate}
\item[\textbf{(a)}] Then, $u\%n\in\left\{  0,1,\ldots,n-1\right\}  $ and
$u\%n\equiv u\operatorname{mod}n$.

\item[\textbf{(b)}] We have $n\mid u$ if and only if $u\%n=0$.

\item[\textbf{(c)}] If $c\in\left\{  0,1,\ldots,n-1\right\}  $ is such that
$c\equiv u\operatorname{mod}n$, then $c=u\%n$.

\item[\textbf{(d)}] We have $u=\left(  u//n\right)  n+\left(  u\%n\right)  $.
\end{enumerate}
\end{proposition}

\begin{proposition}
\label{prop.ent.quo-rem.mod=rem}Let $n$ be a positive integer. Let $u$ and $v$
be integers. Then, $u\equiv v\operatorname{mod}n$ if and only if $u\%n=v\%n$.
\end{proposition}

Proposition \ref{prop.ent.quo-rem.mod=rem} lets us turn congruences between
integers into equalities between their remainders, and vice versa. Here is an
example of how this can be useful:

\begin{exercise}
\label{exe.mod.e2} What is the last (i.e., least significant) digit of the
number $7^{7^{7}}$ ? (Recall that $a^{b^{c}}$ means $a^{\left(  b^{c}\right)
}$, not $\left(  a^{b}\right)  ^{c}$, since the latter could equally well be
written $a^{bc}$.)
\end{exercise}

\begin{proof}
[Solution idea.]With a computer, you could just compute the number (it has
$695975$ digits) and look at its last digit. But this is clearly not a viable
strategy for an exam. (Besides, a modern examiner could equally well ask for
$77^{77^{77}}$.) What to do?

For each positive integer $m$, the last digit of $m$ is the remainder $m\%10$
(why?). So we must compute $7^{7^{7}}\%10$. To this purpose, it suffices to
\textquotedblleft simplify $7^{7^{7}}$ modulo $10$\textquotedblright, that is,
find some smaller integer $m$ such that $7^{7^{7}}\equiv m\operatorname{mod}%
10$. (Once such an $m$ is found, we will then be able to apply Proposition
\ref{prop.ent.quo-rem.mod=rem} and conclude that $7^{7^{7}}\%10=m\%10$. The
remainder $m\%10$ should be easier to compute.)

As a warmup, let us first do this with $7^{7}$. To make this task more
manageable, we observe that $7^{7}=7^{2\cdot3+1}=\left(  7^{2}\right)
^{3}\cdot7$, so we try to simplify $7^{2}$ first. (This is an instance of
\href{https://en.wikipedia.org/wiki/Exponentiation_by_squaring}{\textquotedblleft
exponentiating by squaring\textquotedblright, a well-known computational
trick}.) This is easy: We have $7^{2}=49\equiv-1\operatorname{mod}10$. Hence,
\[
7^{7}=\left(  \underbrace{7^{2}}_{\equiv-1\operatorname{mod}10}\right)
^{3}\cdot7\equiv\left(  -1\right)  ^{3}\cdot7=-7\equiv3\operatorname{mod}10.
\]
Thus, Proposition \ref{prop.ent.quo-rem.mod=rem} yields $7^{7}\%10=3\%10=3$.

Now, let us come back to $7^{7^{7}}$. Knowing that $7^{7}\equiv
3\operatorname{mod}10$, it is tempting to conclude that $7^{7^{7}}\equiv
7^{3}\operatorname{mod}10$ (by substituting $3$ for $7^{7}$ in the exponent).
Unfortunately, this is a misuse of the substitution principle, since we are
not allowed to substitute in an exponent. (Although it would happen to produce
the right answer in this particular case!)

Instead, we look at the first few powers of $7$ modulo $10$:%
\begin{align*}
7^{0}  &  \equiv1\operatorname{mod}10;\\
7^{1}  &  \equiv7\operatorname{mod}10;\\
7^{2}  &  \equiv-1\operatorname{mod}10;\\
7^{3}  &  \equiv-7\operatorname{mod}10;\\
7^{4}  &  \equiv1\operatorname{mod}10;\\
7^{5}  &  \equiv7\operatorname{mod}10;\\
7^{6}  &  \equiv-1\operatorname{mod}10;\\
&  \ldots.
\end{align*}
(We could equally well have used $9$ and $3$ instead of $-1$ and $-7$, since
$-1\equiv9\operatorname{mod}10$ and $-7\equiv3\operatorname{mod}10$. However,
the minus signs feel more natural.) A pattern is easily spotted: The right
hand sides repeat every $4$ lines. That is, we have%
\begin{equation}
7^{k+4}\equiv7^{k}\operatorname{mod}10\ \ \ \ \ \ \ \ \ \ \text{for each }%
k\in\mathbb{N}. \label{sol.mod.e2.period}%
\end{equation}
This pattern is easily proved, too (just observe that $7^{k+4}=7^{k}%
\cdot\underbrace{7^{4}}_{\equiv1\operatorname{mod}10}\equiv7^{k}\cdot
1=7^{k}\operatorname{mod}10$).

Using (\ref{sol.mod.e2.period}), we see (by induction on $m$) that%
\[
7^{k+4m}\equiv7^{k}\operatorname{mod}10\ \ \ \ \ \ \ \ \ \ \text{for each
}k\in\mathbb{N}\text{ and }m\in\mathbb{N}.
\]
Hence, for each nonnegative integer $n$, we have%
\[
7^{n}\equiv7^{n\%4}\operatorname{mod}10
\]
(because $n=n\%4+4\left(  n//4\right)  $). Applying this to $n=7^{7}$, we
obtain $7^{7^{7}}\equiv7^{7^{7}\%4}\operatorname{mod}10$.

Now we need to find $7^{7}\%4$. This is no harder than the remainder
$7^{7}\%10$ we computed above; we get $7^{7}\%4=3$. Hence,
\[
7^{7^{7}}\equiv7^{7^{7}\%4}=7^{3}\equiv-7\operatorname{mod}10.
\]
Thus, Proposition \ref{prop.ent.quo-rem.mod=rem} yields $7^{7^{7}}\%10=\left(
-7\right)  \%10=3$, and we are done.
\end{proof}

Let us also comment a relationship between division with remainder and the
\emph{floor function} (also known as the \emph{rounding-down function}).
Recall the definition of the latter function: If $x$ is a real number, then
the \emph{floor} of $x$ is defined to be the largest integer that is $\leq x$.
This floor is denoted by $\left\lfloor x\right\rfloor $. For instance,
$\left\lfloor 2\right\rfloor =\left\lfloor 2.5\right\rfloor =\left\lfloor
2.8\right\rfloor =2$ and $\left\lfloor \pi\right\rfloor =3$ and $\left\lfloor
0.999\right\rfloor =0$ and $\left\lfloor -2.2\right\rfloor =-3$ (beware: not
$-2$). Note that $\left\lfloor x\right\rfloor \leq x<\left\lfloor
x\right\rfloor +1$ for each real number $x$, and this property uniquely
characterizes $\left\lfloor x\right\rfloor $ among the integers (that is: if
$y$ is an integer satisfying $y\leq x<y+1$, then $y=\left\lfloor
x\right\rfloor $). The following proposition says that the quotient in a
division with remainder is just the floor of the usual (non-integer) quotient:

\begin{proposition}
\label{prop.ent.quo-rem.quo=floor}Let $n$ be a positive integer. Let
$u\in\mathbb{Z}$. Then, $u//n=\left\lfloor \dfrac{u}{n}\right\rfloor $.
\end{proposition}

This is intuitively clear (but see \cite[Proposition 2.8.3]{19s} for a formal proof).

\subsection{More example problems}

So much for the basics. Here are some more interesting problems:

\begin{exercise}
\label{exe.mod.e3}Let $P\left(  x\right)  $ be a univariate polynomial with
integer coefficients. That is, there exist constant integers $u_{0}%
,u_{1},\ldots,u_{d}$ such that each $x\in\mathbb{Z}$ satisfies $P\left(
x\right)  =\sum_{k=0}^{d}u_{k}x^{k}$.

Consider an integer sequence $\left(  s_{0},s_{1},s_{2},\ldots\right)  $
defined recursively by setting
\[
s_{0}=0
\]
and%
\[
s_{i}=P\left(  s_{i-1}\right)  \ \ \ \ \ \ \ \ \ \ \text{for each }i\geq1.
\]


Prove the following: If $a$ and $b$ are two nonnegative integers satisfying
$a\mid b$, then $s_{a}\mid s_{b}$. \medskip

[\textbf{Example:} If $P\left(  x\right)  =x^{2}+1$, then this sequence has
recurrence relation $s_{i}=P\left(  s_{i-1}\right)  =s_{i-1}^{2}+1$, so its
first $7$ entries are%
\begin{align*}
s_{0}  &  =0,\ \ \ \ \ \ \ \ \ \ s_{1}=0^{2}+1=1,\ \ \ \ \ \ \ \ \ \ s_{2}%
=1^{2}+1=2,\ \ \ \ \ \ \ \ \ \ s_{3}=2^{2}+1=5,\\
s_{4}  &  =5^{2}+1=26,\ \ \ \ \ \ \ \ \ \ s_{5}=26^{2}%
+1=677,\ \ \ \ \ \ \ \ \ \ s_{6}=677^{2}+1=458\ 330.
\end{align*}
It is easy to check that $s_{2}$ divides $s_{4}$ and $s_{6}$, and that $s_{3}$
divides $s_{6}$, as the exercise claims.]
\end{exercise}

\begin{proof}
[Solution idea.]This is similar to a property of the Fibonacci sequence we
have seen on worksheet 1 (Exercise 1.1.1 \textbf{(e)}). Unfortunately, there
is no \textquotedblleft addition formula\textquotedblright\ this time, as our
sequence $\left(  s_{0},s_{1},s_{2},\ldots\right)  $ is a lot less
\textquotedblleft well-behaved\textquotedblright\ (at least when $P\left(
x\right)  $ has degree $>1$). However, its simple recursion offers an
advantage to working modulo $n$. To wit, the following holds:

\begin{statement}
\textit{Claim 1:} Let $n\in\mathbb{Z}$, and let $i,j\in\mathbb{N}$ satisfy
$s_{i}\equiv s_{j}\operatorname{mod}n$. Then, $s_{i+1}\equiv s_{j+1}%
\operatorname{mod}n$.
\end{statement}

[\textit{Proof of Claim 1:} We know that $P\left(  x\right)  $ is a polynomial
with integer coefficients. Hence, the substitution principle for congruences
tells us that $s_{i}\equiv s_{j}\operatorname{mod}n$ entails $P\left(
s_{i}\right)  \equiv P\left(  s_{j}\right)  \operatorname{mod}n$%
\ \ \ \ \footnote{If you don't believe this, just check it by hand: Write the
polynomial $P$ as $P\left(  x\right)  =\sum_{k=0}^{d}u_{k}x^{k}$ with integer
coefficients $u_{0},u_{1},\ldots,u_{d}$. Then, $P\left(  s_{i}\right)
=\sum_{k=0}^{d}u_{k}s_{i}^{k}$ and $P\left(  s_{j}\right)  =\sum_{k=0}%
^{d}u_{k}s_{j}^{k}$. However, from $s_{i}\equiv s_{j}\operatorname{mod}n$, we
obtain $s_{i}^{k}\equiv s_{j}^{k}\operatorname{mod}n$ for each $k\in
\mathbb{N}$ (by Proposition \ref{prop.ent.mod.k-power}). Multiplying this
congruence by $u_{k}$ (that is, by the obvious congruence $u_{k}\equiv
u_{k}\operatorname{mod}n$), we obtain $u_{k}s_{i}^{k}\equiv u_{k}s_{j}%
^{k}\operatorname{mod}n$. Summing these congruences over all $k\in\left\{
0,1,\ldots,d\right\}  $ (using (\ref{eq.prop.ent.mod.basics.d.1})), we obtain
$\sum_{k=0}^{d}u_{k}s_{i}^{k}\equiv\sum_{k=0}^{d}u_{k}s_{j}^{k}%
\operatorname{mod}n$. In other words, $P\left(  s_{i}\right)  \equiv P\left(
s_{j}\right)  \operatorname{mod}n$ (since $P\left(  s_{i}\right)  =\sum
_{k=0}^{d}u_{k}s_{i}^{k}$ and $P\left(  s_{j}\right)  =\sum_{k=0}^{d}%
u_{k}s_{j}^{k}$).}. In other words, $s_{i+1}\equiv s_{j+1}\operatorname{mod}n$
(since the recurrence relation of our sequence entails $s_{i+1}=P\left(
s_{i}\right)  $ and $s_{j+1}=P\left(  s_{j}\right)  $). Thus, Claim 1
follows.] \medskip

Claim 1 can easily be leveraged to \textquotedblleft move by multiple
steps\textquotedblright:

\begin{statement}
\textit{Claim 2:} Let $n\in\mathbb{Z}$ and $k\in\mathbb{N}$, and let
$i,j\in\mathbb{N}$ satisfy $s_{i}\equiv s_{j}\operatorname{mod}n$. Then,
$s_{i+k}\equiv s_{j+k}\operatorname{mod}n$.
\end{statement}

[\textit{Proof of Claim 2:} Induction on $k$, using Claim 1 in the induction
step.] \medskip

From Claim 2, in turn, we obtain the following claim, which is essentially a
restatement of the exercise:

\begin{statement}
\textit{Claim 3:} Let $a\in\mathbb{N}$ and $k\in\mathbb{N}$. Then,
$s_{ak}\equiv0\operatorname{mod}s_{a}$.
\end{statement}

[\textit{Proof of Claim 3:} We induct on $k$. The \textit{base case} ($k=0$)
is obvious, since $s_{a\cdot0}=s_{0}=0\equiv0\operatorname{mod}s_{a}$. For the
\textit{induction step}, we fix some $\ell>0$, and assume (as
IH\footnote{Recall: \textquotedblleft IH\textquotedblright\ =
\textquotedblleft induction hypothesis\textquotedblright.}) that Claim 3 holds
for $k=\ell-1$. We must prove that Claim 3 holds for $k=\ell$.

Our IH says that $s_{a\left(  \ell-1\right)  }\equiv0\operatorname{mod}s_{a}$.
This can be rewritten as $s_{a\left(  \ell-1\right)  }\equiv s_{0}%
\operatorname{mod}s_{a}$ (since $s_{0}=0$). Hence, Claim 2 (applied to
$i=a\left(  \ell-1\right)  $ and $j=0$ and $n=s_{a}$ and $k=a$) yields
$s_{a\left(  \ell-1\right)  +a}\equiv s_{0+a}\operatorname{mod}s_{a}$. In view
of $a\left(  \ell-1\right)  +a=a\ell$, this rewrites as%
\[
s_{a\ell}\equiv s_{0+a}=s_{a}\equiv0\operatorname{mod}s_{a}.
\]
In other words, Claim 3 holds for $k=\ell$. This completes the induction step,
so that Claim 3 is proven.] \medskip

Now, if $a$ and $b$ are two nonnegative integers satisfying $a\mid b$, then we
can write $b$ as $b=ak$ for some $k\in\mathbb{N}$, and therefore Claim 3
yields $s_{b}\equiv0\operatorname{mod}s_{a}$; but this says precisely that
$s_{a}\mid s_{b}$. Thus, the exercise is solved.
\end{proof}

The above solution illustrates a general tactic: that of using congruences as
scaffolding to prove divisibilities. Of course, congruences are themselves
divisibilities ($a\equiv b\operatorname{mod}n$ means nothing but $n\mid a-b$),
but it is often more convenient to write them as congruences (particularly as
this makes the substitution principle available).

There are other ways to use congruences as well. One is by exploiting their
\textquotedblleft veto power\textquotedblright\ over equations. The underlying
idea is stupid: If $a,b,n$ are integers such that $a\not \equiv
b\operatorname{mod}n$, then $a\neq b$. This turns out to be surprisingly useful:

\begin{exercise}
\label{exe.mod.e4}Find all pairs $\left(  x,y\right)  $ of nonnegative
integers satisfying $2^{x}-1=3^{y}$.
\end{exercise}

\begin{proof}
[Solution idea.]The only such pairs are $\left(  1,0\right)  $ and $\left(
2,1\right)  $.

In fact, it is easy to check that $\left(  1,0\right)  $ and $\left(
2,1\right)  $ are such pairs; thus, we only need to show that there are no
others. So we assume (for the sake of contradiction) that $\left(  x,y\right)
$ is a pair of nonnegative integers satisfying $2^{x}-1=3^{y}$ and $\left(
x,y\right)  \neq\left(  1,0\right)  $ and $\left(  x,y\right)  \neq\left(
2,1\right)  $. Thus, we can easily see that $x>2$ (why?), so that $2^{x}$ is
divisible by $8$. That is, $2^{x}\equiv0\operatorname{mod}8$. Hence, from
$2^{x}-1=3^{y}$, we obtain $3^{y}=\underbrace{2^{x}}_{\equiv
0\operatorname{mod}8}-1\equiv0-1\equiv7\operatorname{mod}8$. However, a look
at the powers of $3$ modulo $8$ shows that this is impossible:%
\begin{align*}
3^{0}  &  \equiv1\operatorname{mod}8,\\
3^{1}  &  \equiv3\operatorname{mod}8,\\
3^{2}  &  \equiv1\operatorname{mod}8,\\
3^{3}  &  \equiv3\operatorname{mod}8,\\
&  \ldots
\end{align*}
(it is clear that the right hand sides repeat every $2$ lines, and that $7$ is
not among them). Thus, the exercise is solved.
\end{proof}

\subsection{Modular inverses and cancellation}

In general, it is not allowed to cancel factors from congruences, even if the
factors are nonzero. For instance, it is not true that $6a\equiv
6b\operatorname{mod}4$ implies $a\equiv b\operatorname{mod}4$; a
counterexample is easy to find (for instance, $a=0$ and $b=2$). However,
cancellation is allowed when the factor being cancelled is coprime to the
modulus\footnote{The \emph{modulus} in a congruence $a\equiv
b\operatorname{mod}n$ is defined to be the number $n$.}. To wit, the following
holds (\cite[Lemma 3.5.11]{20f}):\footnote{Recall that two integers $u$ and
$v$ are said to be \emph{coprime} if they satisfy $\gcd\left(  u,v\right)
=1$. Instead of saying \textquotedblleft$u$ and $v$ are
coprime\textquotedblright, we also say \textquotedblleft$u$ is coprime to
$v$\textquotedblright.}

\begin{lemma}
\label{lem.ent.coprime.cancel}Let $a,b,c,n$ be integers such that $a$ is
coprime to $n$ and such that $ab\equiv ac\operatorname{mod}n$. Then, $b\equiv
c\operatorname{mod}n$.
\end{lemma}

Better yet, even some sort of \textquotedblleft division\textquotedblright\ is
possible modulo $n$, as long as we divide by an integer coprime to the modulus:

\begin{theorem}
\label{thm.ent.coprime.modinv.b}Let $a$ and $n$ be two coprime integers. Then,
there exists an $a^{\prime}\in\mathbb{Z}$ such that $aa^{\prime}%
\equiv1\operatorname{mod}n$.
\end{theorem}

For example, if $a=2$ and $n=5$, then we can take $a^{\prime}=3$ (since this
satisfies $aa^{\prime}=2\cdot3=6\equiv1\operatorname{mod}5$).

The integer $a^{\prime}$ in Theorem \ref{thm.ent.coprime.modinv.b} is not
unique, but it is \textquotedblleft unique modulo $n$\textquotedblright\ (that
is, any two valid candidates for $a^{\prime}$ are mutually congruent modulo
$n$). We call such an integer $a^{\prime}$ a \emph{modular inverse} to $a$
modulo $n$. It does indeed behave like an inverse for $a$ modulo $n$, in the
sense that multiplication by $a^{\prime}$ undoes multiplication by $a$ modulo
$n$. Thus, Lemma \ref{lem.ent.coprime.cancel} follows easily from Theorem
\ref{thm.ent.coprime.modinv.b} (just pick a modular inverse $a^{\prime}$ for
$a$ modulo $n$, and multiply both sides of the congruence $ab\equiv
ac\operatorname{mod}n$ with $a^{\prime}$).

Theorem \ref{thm.ent.coprime.modinv.b}, in turn, can be proved using the
\emph{Bezout theorem}, which says that if $a$ and $b$ are two integers, then
$\gcd\left(  a,b\right)  $ can be written in the form $\gcd\left(  a,b\right)
=xa+yb$ for some integers $x$ and $y$. We refer to \cite[Theorem 3.5.9
\textbf{(b)}]{20f} for the detailed proof of Theorem
\ref{thm.ent.coprime.modinv.b} (and to \cite[Theorem 3.4.5]{20f} for the proof
of the Bezout theorem\footnote{Actually, proving the Bezout theorem makes for
a nice exercise in strong induction. (Hint: $\gcd\left(  a,b\right)
=\gcd\left(  b,a\right)  =\gcd\left(  a,b-a\right)  $.)}).

Here are some applications of modular inverses and Lemma
\ref{lem.ent.coprime.cancel} in particular. The first is a piece of a greater
result known as the \emph{Chinese Remainder Theorem}\footnote{often
abbreviated \textquotedblleft CRT\textquotedblright}:

\begin{exercise}
\label{exe.mod.e5}Let $p$ and $q$ be two coprime integers. Let $a$ and $b$ be
any two integers. Prove that there exists some integer $x$ such that%
\[
x\equiv a\operatorname{mod}p\ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ x\equiv b\operatorname{mod}q.
\]

\end{exercise}

\begin{proof}
[Solution idea.]We are looking for an integer $x$ satisfying the two
congruences $x\equiv a\operatorname{mod}p$ and $x\equiv b\operatorname{mod}q$.
The first congruence means that $p\mid x-a$; in other words, it means that
$x-a=up$ for some integer $u$. Thus, our $x$ needs to satisfy $x-a=up$ for
some integer $u$; in other words, it needs to have the form $x=a+up$ for some
integer $u$. Now, it remains to find $u$ in such a way that the second
congruence $x\equiv b\operatorname{mod}q$ will be satisfied as well. Upon
substituting $a+up$ for $x$, this congruence $x\equiv b\operatorname{mod}q$
rewrites as $a+up\equiv b\operatorname{mod}q$, which is equivalent to
$up\equiv b-a\operatorname{mod}q$. To find $u$, we thus want to
\textquotedblleft divide $b-a$ by $p$\textquotedblright\ modulo $q$.
Fortunately, we have a tool for this: modular inverses. To wit, Theorem
\ref{thm.ent.coprime.modinv.b} (applied to $p$ and $q$ instead of $a$ and $n$)
yields that there exists some $p^{\prime}\in\mathbb{Z}$ such that $pp^{\prime
}\equiv1\operatorname{mod}q$. Multiplying by this $p^{\prime}$ is like
dividing by $p$. Thus, we set $u=p^{\prime}\left(  b-a\right)  $, and then we
have $up=pu=\underbrace{pp^{\prime}}_{\equiv1\operatorname{mod}q}\left(
b-a\right)  \equiv b-a\operatorname{mod}q$, which is precisely what we wanted.
Thus, setting $u=p^{\prime}\left(  b-a\right)  $ and $x=a+up$ gives us the $x$
we were looking for (or, to be precise, one such $x$).

\begin{fineprint}
Incidentally, when writing up a solution like this, you do not need to
describe the thought process as I did above; all you need is to describe the
$x$ and prove that it works. This allows you to be much shorter. Here is how
the above solution will look like when shortened like this:

\begin{proof}
[First solution to Exercise \ref{exe.mod.e5}.]Theorem
\ref{thm.ent.coprime.modinv.b} (applied to $p$ and $q$ instead of $a$ and $n$)
yields that there exists some $p^{\prime}\in\mathbb{Z}$ such that $pp^{\prime
}\equiv1\operatorname{mod}q$. Consider this $p^{\prime}$. Set $u:=p^{\prime
}\left(  b-a\right)  $, and set $x:=a+up$. Then,%
\[
x=a+u\underbrace{p}_{\equiv0\operatorname{mod}p}\equiv a+u\cdot
0=a\operatorname{mod}p
\]
and%
\[
x=a+\underbrace{up}_{=pu}=a+p\underbrace{u}_{=p^{\prime}\left(  b-a\right)
}=a+\underbrace{pp^{\prime}}_{\equiv1\operatorname{mod}q}\left(  b-a\right)
\equiv a+1\left(  b-a\right)  =b\operatorname{mod}q.
\]
Thus, we have found an integer $x$ satisfying $x\equiv a\operatorname{mod}p$
and $x\equiv b\operatorname{mod}q$. This solves Exercise \ref{exe.mod.e5}.
\end{proof}

This solution is short and slick, but one thing might be missing: symmetry.
This is, of course, a \textquotedblleft first-world problem\textquotedblright%
\ (there is nothing wrong with a non-symmetric solution), but it is a bit
jarring to see the construction of $x$ being \textquotedblleft biased towards
$p$\textquotedblright\ while the conditions that it is meant to satisfy are
symmetric. And indeed, there is an even nicer, symmetric solution around,
although this one might be harder to come up with:

\begin{proof}
[Second solution to Exercise \ref{exe.mod.e5}.]Theorem
\ref{thm.ent.coprime.modinv.b} (applied to $p$ and $q$ instead of $a$ and $n$)
yields that there exists some $p^{\prime}\in\mathbb{Z}$ such that $pp^{\prime
}\equiv1\operatorname{mod}q$. Theorem \ref{thm.ent.coprime.modinv.b} (applied
to $q$ and $p$ instead of $a$ and $n$) yields that there exists some
$q^{\prime}\in\mathbb{Z}$ such that $qq^{\prime}\equiv1\operatorname{mod}p$.
Consider these integers $p^{\prime}$ and $q^{\prime}$. Now, set $x=pp^{\prime
}b+qq^{\prime}a$. Then,%
\[
x=\underbrace{p}_{\equiv0\operatorname{mod}p}p^{\prime}%
b+\underbrace{qq^{\prime}}_{\equiv1\operatorname{mod}p}a\equiv0p^{\prime
}b+1a=a\operatorname{mod}p
\]
and similarly $x\equiv b\operatorname{mod}q$. So we have found our $x$, and
rather explicitly in fact.
\end{proof}
\end{fineprint}
\end{proof}

Here is another application of modular inverses:

\begin{exercise}
\label{exe.mod.e6}Let $p$ be a prime number. Let $a,b\in\mathbb{Z}$ and
$k\in\left\{  0,1,\ldots,p-1\right\}  $ be such that $a\equiv
b\operatorname{mod}p$. Prove that
\[
\dbinom{a}{k}\equiv\dbinom{b}{k}\operatorname{mod}p.
\]


[\textbf{Example:} If $p=3$ and $a=5$ and $b=8$ and $k=2$, then this is saying
that $\dbinom{5}{2}\equiv\dbinom{8}{2}\operatorname{mod}3$. Note how this
would be false for $k=3$. In a way, this is a -- somewhat limited -- instance
of the substitution principle for congruences holding even beyond its
\textquotedblleft reasonable\textquotedblright\ assumptions.]
\end{exercise}

\begin{proof}
[Solution idea.]First of all, this all wouldn't make sense if $\dbinom{a}{k}$
and $\dbinom{b}{k}$ were not integers. Fortunately, $\dbinom{a}{k}$ and
$\dbinom{b}{k}$ are indeed integers (see, e.g., \cite[proof of Theorem
1.3.16]{19fco} for the reason why).

The definition of binomial coefficients yields%
\begin{align}
\dbinom{a}{k}  &  =\dfrac{a\left(  a-1\right)  \left(  a-2\right)
\cdots\left(  a-k+1\right)  }{k!}\ \ \ \ \ \ \ \ \ \ \text{and}%
\label{sol.mod.e6.ak}\\
\dbinom{b}{k}  &  =\dfrac{b\left(  b-1\right)  \left(  b-2\right)
\cdots\left(  b-k+1\right)  }{k!}. \label{sol.mod.e6.bk}%
\end{align}
Now, the substitution principle for congruences yields
\[
a\left(  a-1\right)  \left(  a-2\right)  \cdots\left(  a-k+1\right)  \equiv
b\left(  b-1\right)  \left(  b-2\right)  \cdots\left(  b-k+1\right)
\operatorname{mod}p
\]
(since $a\equiv b\operatorname{mod}p$). In view of (\ref{sol.mod.e6.ak}) and
(\ref{sol.mod.e6.bk}), we can rewrite this congruence as%
\begin{equation}
k!\cdot\dbinom{a}{k}\equiv k!\cdot\dbinom{b}{k}\operatorname{mod}p.
\label{sol.mod.e6.cong}%
\end{equation}
If we could cancel $k!$ from this congruence, we would be done.

Fortunately, we can indeed do this. Indeed, if you know some basic number
theory, you will recognize that $k\in\left\{  0,1,\ldots,p-1\right\}  $
entails that the integer $k!$ is coprime to $p$, and therefore Lemma
\ref{lem.ent.coprime.cancel} allows us to cancel $k!$ from
(\ref{sol.mod.e6.cong}). If you don't, you can get to the same conclusion by a
step-by-step procedure: After all, $k!$ is the product $1\cdot2\cdot
\cdots\cdot k$. Thus, the congruence (\ref{sol.mod.e6.cong}) rewrites as
\begin{equation}
1\cdot2\cdot\cdots\cdot k\cdot\dbinom{a}{k}\equiv1\cdot2\cdot\cdots\cdot
k\cdot\dbinom{b}{k}\operatorname{mod}p. \label{sol.mod.e6.con2}%
\end{equation}
However, each of the $k$ integers $1,2,\ldots,k$ is coprime to $p$ (since
$k\in\left\{  0,1,\ldots,p-1\right\}  $ and since $p$ is prime) and therefore
can be cancelled from a congruence modulo $p$ (by Lemma
\ref{lem.ent.coprime.cancel}). Hence, we can cancel all these $k$ integers
$1,2,\ldots,k$ from (\ref{sol.mod.e6.con2}), one after the other. At the end,
we obtain $\dbinom{a}{k}\equiv\dbinom{b}{k}\operatorname{mod}p$, so the
exercise is solved.
\end{proof}

\subsection{Class problems}

The following problems are to be discussed during class.

\begin{exercise}
\label{exe.mod.c1}Prove that there exist no two rational numbers $a$ and $b$
such that $a^{2}+b^{2}=3$.
\end{exercise}

\begin{exercise}
\label{exe.mod.c2}A sequence $\left(  a_{0},a_{1},a_{2},\ldots\right)  $ is
said to be \emph{purely periodic} if there exists some positive integer $p$
such that all $n\in\mathbb{N}$ satisfy $a_{n}=a_{n+p}$ (that is, the sequence
consists of the same $p$ entries, repeated over and over without any changes
to their values or order). Such an integer $p$ is then called a \emph{period}
of this sequence.

Let $k\in\mathbb{N}$, and let $m$ be a positive integer. Define a sequence
$\left(  c_{0},c_{1},c_{2},\ldots\right)  $ of integers by setting
\[
c_{n}=\dbinom{n}{k}\%m\ \ \ \ \ \ \ \ \ \ \text{for each }n\in\mathbb{N}.
\]
Prove that this sequence is purely periodic. \medskip

[\textbf{Example:} If $k=2$ and $m=2$, then this sequence is
\[
\left(  0,0,1,1,0,0,1,1,0,0,1,1,\ldots\right)  ,
\]
which is purely periodic with a period of $4$ (the entries $0,0,1,1$ repeat
endlessly). Note that this period is larger than $m$, which illustrates that
the substitution principle for congruences does not apply to polynomials with
non-integer coefficients: For instance, we have $1\equiv3\operatorname{mod}2$,
but $\dbinom{1}{2}\not \equiv \dbinom{3}{2}\operatorname{mod}2$.]
\end{exercise}

\begin{exercise}
\label{exe.mod.c3}Prove that there exist infinitely many primes that are
congruent to $3$ modulo $4$. \medskip

[\textbf{Hint:} Recall
\href{https://t5k.org/notes/proofs/infinite/euclids.html}{Euclid's famous
proof that there are infinitely many primes}.]
\end{exercise}

\begin{exercise}
\label{exe.mod.c4}Let $p$ be a prime.

\begin{enumerate}
\item[\textbf{(a)}] Prove that $p\mid\dbinom{p}{k}$ for each $k\in\left\{
1,2,\ldots,p-1\right\}  $.

\item[\textbf{(b)}] Prove that $\left(  a+b\right)  ^{p}\equiv a^{p}%
+b^{p}\operatorname{mod}p$ for any integers $a$ and $b$.

\item[\textbf{(c)}] Prove that $a^{p}\equiv a\operatorname{mod}p$ for any
integer $a$.

\item[\textbf{(d)}] Prove that $a^{p-1}\equiv1\operatorname{mod}p$ for any
integer $a$ that is not divisible by $p$.
\end{enumerate}
\end{exercise}

Parts \textbf{(c)} and \textbf{(d)} of Exercise \ref{exe.mod.c4} are known as
\emph{Fermat's Little Theorem}. \medskip

The following exercise is another form of the Chinese Remainder Theorem:

\begin{exercise}
Let $p$ and $q$ be two coprime positive integers. Prove that the map%
\begin{align*}
\left\{  0,1,\ldots,pq-1\right\}   &  \rightarrow\left\{  0,1,\ldots
,p-1\right\}  \times\left\{  0,1,\ldots,q-1\right\}  ,\\
n  &  \mapsto\left(  n\%p,\ n\%q\right)
\end{align*}
is bijective. (In other words, an element $n\in\left\{  0,1,\ldots
,pq-1\right\}  $ is uniquely determined by its two remainders $n\%p$ and
$n\%q$, and every pair of possible remainders comes from a unique
$n\in\left\{  0,1,\ldots,pq-1\right\}  $.)
\end{exercise}

\begin{exercise}
\label{exe.mod.c5}Let $p$ be a prime. Prove that there exists a positive
integer $n$ such that $p\mid2^{n}+3^{n}+6^{n}-1$.
\end{exercise}

\subsection{Homework exercises}

Solve 4 of the 10 exercises below and upload your solutions on gradescope by
October 17.

\begin{exercise}
Let $b$ be an odd positive integer. Prove that the second-to-last digit of
$b^{2}$ (in decimal notation) is even. \medskip

[\textbf{Example:} The second-to-last digit of $37^{2}=1369$ is $6$, which is even.]
\end{exercise}

\begin{exercise}
\label{exe.mod.h1}Let $p$ be a prime. Let $k\in\mathbb{N}$.

\begin{enumerate}
\item[\textbf{(a)}] Prove that
\[
\dbinom{k}{p-1}\equiv%
\begin{cases}
1, & \text{if }k\equiv-1\operatorname{mod}p;\\
0, & \text{if }k\not \equiv -1\operatorname{mod}p
\end{cases}
\ \ \operatorname{mod}p.
\]


\item[\textbf{(b)}] Prove that
\[
\dbinom{k}{p}\equiv\left\lfloor \dfrac{k}{p}\right\rfloor \operatorname{mod}%
p.
\]

\end{enumerate}
\end{exercise}

\begin{exercise}
\label{exe.mod.h2new}The number $0$ is written on a blackboard. You are
allowed to take a number $x$ written on the blackboard and replace it by
either $3x+1$ or $\left\lfloor x/2\right\rfloor $ (you choose which). Prove
that you can obtain any nonnegative integer by a sequence of such operations.
\medskip

[\textbf{Example:} If you want to obtain $19$, you can proceed as follows:
$0\overset{A}{\rightarrow}1\overset{A}{\rightarrow}4\overset{A}{\rightarrow
}13\overset{B}{\rightarrow}6\overset{A}{\rightarrow}19$. Here, an
\textquotedblleft$\overset{A}{\rightarrow}$\textquotedblright\ arrow means a
step of the form $x\mapsto3x+1$, whereas a \textquotedblleft%
$\overset{B}{\rightarrow}$\textquotedblright\ arrow means a step of the form
$x\mapsto\left\lfloor x/2\right\rfloor $.]
\end{exercise}

\begin{exercise}
Let $n>3$ be an integer. Consider a collection of $n$ stones, weighing
$1,2,\ldots,n$ pounds, respectively. For what values of $n$ is it possible to
subdivide this collection into three piles that have the same total masses?
(The piles need not have the same number of stones, only the same total
weight.) \medskip

[\textbf{Example:} This is possible for $n=5$ (since $1+4=2+3=5$) and for
$n=8$ (since $1+3+8=2+4+6=5+7$) but not for $n=7$ (why not?).]
\end{exercise}

\begin{exercise}
\label{exe.mod.h3}Let $p$ and $q$ be two coprime positive integers. Prove that%
\[
\sum_{k=0}^{p-1}\left\lfloor \dfrac{kq}{p}\right\rfloor =\dfrac{\left(
p-1\right)  \left(  q-1\right)  }{2}.
\]

\end{exercise}

\begin{exercise}
\label{exe.mod.h4}Let $P\left(  x\right)  $ and $\left(  s_{0},s_{1}%
,s_{2},\ldots\right)  $ be as in Exercise \ref{exe.mod.e3}. Prove that%
\[
\gcd\left(  s_{a},s_{b}\right)  =\left\vert s_{\gcd\left(  a,b\right)
}\right\vert \ \ \ \ \ \ \ \ \ \ \text{for any }a,b\in\mathbb{N}.
\]


[\textbf{Hint:} Show that $\gcd\left(  s_{a},s_{b}\right)  =\gcd\left(
s_{a},s_{b-a}\right)  $ whenever $a\leq b$; then argue by strong induction as
in the proof of the Bezout theorem (\cite[proof of Theorem 3.4.5]{20f}).]
\end{exercise}

\begin{exercise}
For any $n\in\mathbb{N}$, set%
\[
u_{n}:=\sum_{k=0}^{n}\dfrac{n!}{k!}=\dfrac{n!}{0!}+\dfrac{n!}{1!}%
+\cdots+\dfrac{n!}{n!}.
\]
(This is an integer, since $\dfrac{n!}{k!}=\left(  k+1\right)  \left(
k+2\right)  \cdots n$ for any $k\leq n$. Combinatorially, $u_{n}$ is the
number of all tuples of distinct elements from the set $\left\{
1,2,\ldots,n\right\}  $. For instance, for $n=2$, we have $u_{2}=5$, counting
the tuples $\left(  {}\right)  $, $\left(  1\right)  $, $\left(  2\right)  $,
$\left(  1,2\right)  $ and $\left(  2,1\right)  $.)

Prove that if $x$ and $y$ are two nonnegative integers, then $u_{x}-u_{y}$ is
divisible by $x-y$. \medskip

[\textbf{Hint:} First, express $u_{n}$ recursively through $u_{n-1}$.]
\end{exercise}

\begin{exercise}
\label{exe.mod.h5}Let $p$ be a prime such that $p\equiv3\operatorname{mod}4$.

\begin{enumerate}
\item[\textbf{(a)}] Prove that there exists no $c\in\mathbb{Z}$ such that
$c^{2}\equiv-1\operatorname{mod}p$.

\item[\textbf{(b)}] Prove that if $a,b\in\mathbb{Z}$ are two integers
satisfying $a^{2}+b^{2}\equiv0\operatorname{mod}p$, then $a$ and $b$ are
multiples of $p$.

\item[\textbf{(c)}] Prove that there exist no two rational numbers $a$ and $b$
such that $a^{2}+b^{2}=p$.
\end{enumerate}

[\textbf{Hint:} For part \textbf{(a)}, apply Exercise \ref{exe.mod.c4}
\textbf{(d)} and note that $\left(  p-1\right)  /2$ is odd. For part
\textbf{(b)}, use modular inverses modulo $p$. Note that part \textbf{(c)}
generalizes Exercise \ref{exe.mod.c1}.]
\end{exercise}

\begin{exercise}
\label{exe.mod.h6}Prove that there exist infinitely many primes that are
congruent to $1$ modulo $4$. \medskip

[\textbf{Hint:} You can use Exercise \ref{exe.mod.h5} \textbf{(a)}.]
\end{exercise}

\begin{exercise}
Let $n$ be a positive integer. Prove that there exist integers $a$ and $b$
such that $n\mid4a^{2}+9b^{2}-1$.\medskip

[\textbf{Hint:} Write $n$ as $n=2^{i}m$, where $m$ is odd. Now find a solution
to the congruence $4a^{2}+9b^{2}\equiv1\operatorname{mod}2^{i}$ and a solution
of the congruence $4a^{2}+9b^{2}\equiv1\operatorname{mod}m$. Combine them
using the Chinese Remainder Theorem to obtain a solution of $4a^{2}%
+9b^{2}\equiv1\operatorname{mod}n$.]
\end{exercise}

\begin{thebibliography}{99999999}                                                                                         %


\bibitem[Grinbe18]{19fco}Darij Grinberg, \textit{Enumerative Combinatorics
(Drexel Fall 2019 Math 222 notes)}, 18 September 2020.\newline\url{http://www.cip.ifi.lmu.de/~grinberg/t/19fco/n/n.pdf}

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

\bibitem[Grinbe20]{20f}Darij Grinberg, \textit{Math 235: Mathematical Problem
Solving}, 10 August 2021.\newline\url{https://www.cip.ifi.lmu.de/~grinberg/t/20f/mps.pdf}
\end{thebibliography}


\end{document}