Lemma 1
Let $m \ne 0, 1$ be a square-free integers.
Then $\mathbb{Q}(\sqrt m)$ is a quadratic number field.
Proof:
It suffices to prove that the polynomial $x^2 - m$ is irreducible in $\mathbb{Q}[x]$.
If $m \lt 0$, the polynomial has no rational roots.
Hence the assertion is clear.
If $m \gt 1$, the assertion follows from Eisenstein's criterion.
Lemma 2
Let $m \ne 0, 1$ and $m' \ne 0, 1$ be square-free integers.
Suppose $\mathbb{Q}(\sqrt m) = \mathbb{Q}(\sqrt m')$.
Then $m = m'$.
Proof:
By Lemma 1, $\mathbb{Q}(\sqrt m)$ and $\mathbb{Q}(\sqrt m')$ are quadratic number fields.
Hence there exist rational integers $a, b$ such that $\sqrt m = a + b\sqrt m'$.
Taking the traces of the both sides, we get $0 = 2a$.
Hence $\sqrt m = b\sqrt m'$.
Squaring the both sides, we get $m = b^2 m'$.
Since $m$ is square-free, $m = m'$.
Lemma 3
Let $D \ne 0$ be a non-square integer.
Then $D$ can be written as $D = f^2 c$, where $f \gt 0$ is an integer and $c \ne 1$ is a square-free integer.
Proof:
We can assume $D \gt 0$ without loss of generality.
Let $D = p_1^{n_1}\cdots p_r^{n_r}$, where $p_1,\cdots, p_r$ are distinct prime numbers.
Let $n_k = 2m_k + e_k$ for $k = 1,\cdots, r$, where $m_k$ is an integer and $e_k = 0$ or $1$.
Let $f = p_1^{m_1}\cdots p_r^{m_r}$ and $c = p_1^{e_1}\cdots p_r^{e_r}$ and we are done.
Lemma 4
Let $K$ be a quadratic number field.
Then there exists a unique square-free integer $m$ such that $K = \mathbb{Q}(\sqrt m)$.
Proof:
By Lemma 2, it suffices to prove the existence of such $m$.
Let $\alpha$ be an irrational element of $K$.
Then $K = \mathbb{Q}(\alpha)$.
Since $(K \colon \mathbb{Q}) = 2$, there exist rational integers $a, b, c$ such that $a \ne 0$ and $\alpha$ is a root of the polynomial $ax^2 + bx + c$.
Let $D = b^2 - 4ac$.
Then $\alpha = (-b + \sqrt D)/2a$ or $(-b - \sqrt D)/2a$.
Hence $K = \mathbb{Q}(\sqrt D)$.
By Lemma 3, $D$ can be written as $D = f^2 m$, where $f \gt 0$ is an integer and $m \ne 1$ is a square-free integer.
Clearly $K = \mathbb{Q}(\sqrt m)$.
Lemma 5
Let $m$ be an integer.
Let $k, l$ be integers such that $k^2 \equiv l^2 m$ (mod $4$).
If $m \equiv 1$ (mod $4$), then $k \equiv l$ (mod $2$).
If $m \equiv 2, 3$ (mod $4$), then $k$ and $l$ are both even.
Proof:
We first note the following facts.
If $k$ is even, then $k^2 \equiv 0$ (mod $4$).
If $k$ is odd, then $k^2 \equiv 1$ (mod $4$).
Case 1: $m \equiv 1$ (mod $4$)
If $k$ is even, then $0 \equiv l^2$ (mod $4$).
Hence $l$ is even.
If $k$ is odd, then $1 \equiv l^2$ (mod $4$).
Hence $l$ is odd.
Case 2: $m \equiv 2$ (mod $4$)
If $k$ is even, then $0 \equiv l^2 2$ (mod $4$).
Hence $l$ is even.
If $k$ is odd, then $1 \equiv l^2 2$ (mod $4$).
This is impossible.
Case 3: $m \equiv 3$ (mod $4$)
If $k$ is even, then $0 \equiv l^2 3$ (mod $4$).
Hence $l$ is even.
If $k$ is odd, then $1 \equiv l^2 3$ (mod $4$).
This is impossible.
Lemma 6
Let $m \ne 0, 1$ be a square-free integer.
If $m \equiv 1$ (mod $4$), then let $\omega = (1 + \sqrt m)/2$.
If $m \equiv 2, 3$ (mod $4$), then let $\omega = \sqrt m$.
Then the ring of algebraic integers of $\mathbb{Q}(\sqrt m)$ is a free $\mathbb{Z}$-module with a basis $1, \omega$.
Proof:
Let $K = \mathbb{Q}(\sqrt m)$.
Let $\mathcal{O}_K$ be the ring of algebraic integers of $K$.
Since it is easy to see that $\omega \in \mathcal{O}_K$,
it suffices to prove that $\mathcal{O}_K \subset \mathbb{Z} + \mathbb{Z}\omega$.
Let $\alpha = a + b\sqrt m$ be an element of $\mathcal{O}_K$, where $a$ and $b$ are rational numbers.
$Tr_{K/\mathbb{Q}}(\alpha) = 2a$ is a rational integer.
$N_{K/\mathbb{Q}}(\alpha) = a^2 - b^2 m$ is a rational integer.
Hence $4(a^2 - m b^2) = (2a)^2 - (2b)^2 m$ is a rational integer.
Hence $(2b)^2 m$ is a rational integer.
Since $m$ is square-free, $2b$ is a rational integer.
Let $k = 2a, l = 2b$.
Then $k^2 \equiv l^2 m$ (mod $4$).
Case 1 : $m \equiv 1$ (mod $4$)
By Lemma 5, $k \equiv l$ (mod $2$).
Hence there exists a rational integer $t$ such that $k = l + 2t$.
Then $\alpha = a + b\sqrt m = (k + l \sqrt m)/2 = (l + 2t + l\sqrt m)/2 = t + l\omega$.
Hence $\alpha \in \mathbb{Z} + \mathbb{Z}\omega$.
Case 2 : $m \equiv 2, 3$ (mod $4$)
By Lemma 5, $k$ and $l$ are both even.
Hence $a$ and $b$ are both rational integers.
Hence $\alpha \in \mathbb{Z} + \mathbb{Z}\omega$.
Lemma 7
Let $m \ne 0, 1$ be a square-free integers.
If $m \equiv 1$ (mod $4$), then the discriminant of $\mathbb{Q}(\sqrt m)$ is $m$.
If $m \equiv 2, 3$ (mod $4$), then the discriminant of $\mathbb{Q}(\sqrt m)$ is $4m$.
Proof:
This follows immediately from Lemma 6.
Lemma 8
Let $K$ be a quadratic number field.
Let $D$ be the discriminant of $K$.
Then $K = \mathbb{Q}(\sqrt D)$.
Proof:
By Lemma 4, there exists a unique square-free integer $m$ such that $K = \mathbb{Q}(\sqrt m)$.
By Lemma 7, $D = m$ or $4m$.
Hence $K = \mathbb{Q}(\sqrt D)$.
Proposition
Let $D \ne 0$ be a non-square integer such that $D \equiv 0$ (mod $4$) or $D \equiv 1$ (mod $4$).
Then $D$ can be written as $D = f^2 d$, where $f \gt 0$ is an integer
and $d$ is the discriminant of a unique quadratic number field.
Proof:
Since the uniqueness of the quadratic number field follows from Lemma 8,
it suffices to prove the existence.
Case 1: $D \equiv 0$ (mod 4)
By Lemma 3, $D/4$ can be written as $D/4 = g^2m$, where $g \gt 0$ is an integer and $m \ne 1$ is a square-free integer.
Hence, $D = 4g^2m$.
If $m \equiv 1$ (mod $4$), then by Lemma 7, $m$ is the discriminant of $\mathbb{Q}(\sqrt m)$.
Let $f = 2g, d = m$, and we are done.
If $m \equiv 2, 3$ (mod $4$), then by Lemma 7, $4m$ is the discriminant of $\mathbb{Q}(\sqrt m)$.
Let $f = g, d = 4m$, and we are done.
Case 2: $D \equiv 1$ (mod $4$)
By Lemma 3, $D$ can be written as $D = f^2m$, where $f \gt 0$ is an integer and $m \ne 1$ is a square-free integer.
Note that $f^2 \equiv 0, 1$ (mod $4$).
However, if $f^2 \equiv 0$ (mod $4$), then $D \equiv 0$ (mod $4$).
This is a contradiction. Hence $f^2 \equiv 1$ (mod $4$).
Hence $D \equiv m$ (mod $4$).
Hence $m \equiv 1$ (mod $4$).
Hence $m$ is the discriminant of $\mathbb{Q}(\sqrt m)$.