I would like to know whether I have correctly proved the following result. My book gave a different proof. My concern is primarily with correctness and notation. Also, we are given: if $3 \nmid n$ then $n=3k+1$ or $n=3k+2$ and so $3\mid(n^2-1)$. $k \in \mathbb{Z}$
$$\text{Let} \space n \in \mathbb{Z}, \text{ Prove that } 3\mid(2n^2+1) \text{ if and only if } 3 \nmid n.$$
$$\text{Proof: We first prove the if direction of the biconditional, } 3\nmid n\implies 3\mid(2n^2+1) \\ \text{Hence, we have the following two cases. } $$ $$\text{1: n=3k+1} \\ \text{2: n=3k+2}\\ \text{Case 1: }2n^2+1=2(3k+1)^2+1= 3(6k^2+4k+1)\\ \text{Since } 6k^2+4k+1 \text{ is an integer } \\ \therefore 3\mid(2n^2+1) \\ \text{Case 2: Similar, therefore omitted.}$$ $$\text{Finally, for the if only direction we use the contrapositive, } 3\mid n\implies 3\nmid(2n^2+1)$$ $$\text{We know $3\mid n$. Thus, } n=3k, k\in \mathbb{Z} \\ \text{Then, } 2n^2+1=3(6k^2)+1\\ 6k^2 \text{ is an integer } \\ \therefore 3\nmid(2n^2+1)$$
$$\text{Now we conclude that: }3\mid(2n^2+1) \text{ if and only if } 3 \nmid n \text{ } \blacksquare$$
I might use too many words but I try to be as clear as possible since I am still learning how to do proofs correctly.