I want to make sure I'm doing this right. This is what I'm trying to do: Let $p$ be an integer other than $0,\pm 1$ . Prove that p is prime if for each $a\in \Bbb Z$ either $(a,p)=1$ or $ p\mid a $ .
here's what I have so far:
First note that $(-m) \mid p$ if and only if $m \mid p$, so we may consider only positive divisors of $p$. By the same reasoning, $-p$ is prime if and only if $p$ is prime, so we may assume $p>1$. If $p \mid a$ then $(a,p)=p$. Thus either $(a,p)=1$ or $(a,p)=p$. Consider the set $\mathbf S$ of all positive divisors $m$ of $p$, that is $$ \mathbf S=\{ m\in \Bbb Z : m\gt 0 \text{ and } p=mn \text{ for some } n\in \Bbb Z\}. $$ Since $a$ may be any integer, suppose $a=m$, that is, suppose $a$ is a positive divisor of $p$. Then $(a,p)=(m,p)=m$. But we know that either $(a,p)=1$ or $(a,p)=p$. Hence either $m=1$ or $m=p$. Therefore the only divisors of $p$ are $\pm 1$ and $\pm p$, and hence $p$ is prime.
I'm a little bit confused about the justification for replacing $a$ with $m$.