I'm learning Real Analysis by myself and I wanted to prove that if a prime $p$ divides $n^2$ where $n$ is an integer, then $p$ divides $n$ itself. I saw that proving this is the same as saying that the prime factors of $n^2$ are "the same" than those of $n$.
In this case, assume there exists a prime factor $a_q$ in $n^2$ which is not in $n$ (proof by contradiction). By Fundamental Theorem of Arithmetic, we can represent $n^2$ as $n^2= a_1 * a_2 * ... * a_x * a_q$, where every $a$ is prime and $n=k_1 * k_2 * ... * k_y$ (every $k$ is also prime). We know that $\frac{n^2}{n}=n$. So (by susbstituting):
$\frac{n^2}{n}= \frac{a_1*...*a_x*a_q}{k_1*...*k_y}=n \rightarrow \frac{a_1*...*a_x}{k_1*...*k_y}=\frac{n}{a_q}$
Because $\frac{n}{a_q}$ it's not an integer (initial statement), there's at least one $a_s$ in the left side of the equation that is not divisible by any $k$. Now we have two factors of $n^2$ that don't divide $n$. We can repeat this process,
$\frac{a_1*...*a_x*a_s}{k_1*...*k_y}=\frac{n}{a_q} \rightarrow \frac{a_1*...*a_x}{k_1*...*k_y}=\frac{n}{a_q*a_s}$,
for each prime factor of $n^2$ which means that there's no factor $a_i$ in $n^2$ divisible by any factor $k_j$ of $n$. But we knew that $\frac{n^2}{n}=n$, hence we have a contradiction ($n^2$ is not divisible by $n$). So there's no prime factor $p$ in $n^2$ that does not divide $n$ itself $\rightarrow$ every prime factor $p$ in $n^2$ also divides $n$.
I'm obviously not an expert in demonstrations so I want to know if this is a valid argument. I'm also aware of Euclid's Lemma, but for this case, ignore it.