Let $a,b\in \mathbb{Z}$. It is a known fact that if there exists $x,y\in\mathbb{Z}$ such that $ax+by=1$, then 1 is the $\gcd(a,b)$. Let $d\in\mathbb{Z}$. Suppose there exists $x,y\in\mathbb{Z}$ such that $ax+by=d$, Prove that $d=1$ is the only integer for what this implies $\gcd(a,b)=d$.
An exercise in an introductory Algebra book just asks you to JUSTIFY that 1 is the only integer that satisfies this. This IS in one of the first chapters, before introducing Diophantine equations or Congruences. I solve it like this: Let $d$ be a positive integer such that there exists $x,y\in\mathbb{Z}$ with $ax+by=d$. If $m$ is $\gcd(a,b)$, then $m|d$, because $d$ is a linear integer combination of $a$ and $b$. Therefore $d$ is a multiple of $m$, which constitutes an infinite set. The only case in which we can conclude that $m=d$ is when $d=1$, because the only positive divisor of 1 is 1 itself. Other numbers have at least two divisors (itself and 1).
I think it was a good justification and answered the exercise in the book. But, on the other hand, this argument is not a proof, because, at first glance, nothing prevents other facts from causing some specific $d$ to have the desired property. A counterexample doesn't work here. How to formally prove this?