\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}

\title{Primes and the Euclidean Algorithm}
\date{02-10-2025}

\begin{document}

\maketitle

\section{Introduction}

Let $a, b \in \mathbb{Z}$. We say that $a$ \textbf{divides} $b$, written $a \mid b$, if there exists $c \in \mathbb{Z}$ such that $b = ac$.

\begin{definition}
A positive integer $p > 1$ is called \textbf{prime} if its only positive divisors are $1$ and $p$ itself.
\end{definition}

\begin{definition}
For integers $a$ and $b$, not both zero, the \textbf{greatest common divisor} $\gcd(a,b)$ is the largest positive integer that divides both $a$ and $b$.
\end{definition}

\section{The Euclidean Algorithm}

The Euclidean algorithm is an efficient method for computing the greatest common divisor of two integers.

\begin{theorem}[Division Algorithm]
Let $a, b \in \mathbb{Z}$ with $b > 0$. Then there exist unique integers $q$ and $r$ such that
\[
a = bq + r \quad \text{with} \quad 0 \leq r < b.
\]
Here $q$ is called the \textbf{quotient} and $r$ is called the \textbf{remainder}.
\end{theorem}

\begin{theorem}
If $a = bq + r$, then $\gcd(a,b) = \gcd(b,r)$.
\end{theorem}

\begin{proof}
Let $d = \gcd(a,b)$. Then $d \mid a$ and $d \mid b$. Since $r = a - bq$, we have $d \mid r$. Thus $d$ is a common divisor of $b$ and $r$, so $d \leq \gcd(b,r)$.

Conversely, let $d' = \gcd(b,r)$. Then $d' \mid b$ and $d' \mid r$. Since $a = bq + r$, we have $d' \mid a$. Thus $d'$ is a common divisor of $a$ and $b$, so $d' \leq \gcd(a,b) = d$.

Therefore $d = \gcd(b,r)$.
\end{proof}

\subsection{The Algorithm}

To compute $\gcd(a,b)$ where $a \geq b > 0$:
\begin{enumerate}
\item Apply the division algorithm repeatedly:
\begin{align*}
a &= bq_1 + r_1, \quad 0 \leq r_1 < b \\
b &= r_1 q_2 + r_2, \quad 0 \leq r_2 < r_1 \\
r_1 &= r_2 q_3 + r_3, \quad 0 \leq r_3 < r_2 \\
&\vdots \\
r_{n-2} &= r_{n-1} q_n + r_n, \quad 0 \leq r_n < r_{n-1} \\
r_{n-1} &= r_n q_{n+1} + 0
\end{align*}

\item The last non-zero remainder $r_n$ is $\gcd(a,b)$.
\end{enumerate}

\begin{theorem}[Bézout's Identity]
Let $a, b \in \mathbb{Z}$, not both zero, and let $d = \gcd(a,b)$. Then there exist integers $x$ and $y$ such that
\[
ax + by = d.
\]
\end{theorem}

\begin{proof}
Consider the set $S = \{ax + by : x, y \in \mathbb{Z} \text{ and } ax + by > 0\}$. This set is non-empty (contains $|a|$ or $|b|$) and bounded below by $1$, so by the well-ordering principle it has a smallest element, say $d' = ax_0 + by_0$.

We claim that $d' = \gcd(a,b)$. First we show that $d' \mid a$. By the division algorithm, write $a = d'q + r$ with $0 \leq r < d'$. Then
\[
r = a - d'q = a - (ax_0 + by_0)q = a(1 - x_0q) + b(-y_0q).
\]
If $r > 0$, then $r \in S$ and $r < d'$, contradicting the minimality of $d'$. Thus $r = 0$ and $d' \mid a$. Similarly, $d' \mid b$.

So $d'$ is a common divisor of $a$ and $b$, hence $d' \leq d = \gcd(a,b)$.

Conversely, since $d \mid a$ and $d \mid b$, we have $d \mid (ax_0 + by_0) = d'$. Thus $d \leq d'$.

Therefore $d = d'$, completing the proof.
\end{proof}

\end{document}
