We have the following generalization: Let $K$ be a quadratic extension of $\mathbb Q$, $\mathcal O_K$ the ring of integers, $q$ an odd prime of $\mathbb Q$ unramified in $K$, and $x \in \mathcal O_K$ prime to $q$. Let $e = \frac{ q-1}{2}$ if $q$ splits in $K$ or $e=\frac{q+1}{2}$ if $q$ is inert in $K$.
Then $x^{e} \in \mathbb Z + q \mathcal O_K $ if and only if $\left( \frac{\operatorname{Norm}(x) }{q} \right)=1$ and $\operatorname{tr} (x^e) \in q \mathbb Z$ if and only if $\left( \frac{\operatorname{Norm}(x) }{q} \right)=-1$.
Proof: $x$ is an element of $(\mathcal O_K/q)^*$. The element $\frac{x}{\overline{x}}$key identity here is a norm $1$ element ofthat $(\mathcal O_K/q)^*$.,$$x^q = \operatorname{Frob}_q(x) = \begin{cases} x & \textrm{if }q\textrm{ split} \\ \overline{x}& \textrm{if }q\textrm{ inert} \end{cases}$$ which lies incombined with the group of norm $1$ elements, which has order $2e$, so $( \frac{x}{\overline{x}})^e = \frac{ x^e}{ \overline{x^e}}$ has order dividing $2$ and thus is $\pm 1$. If it is $+1$ then $x^e$ lies in $\mathbb Z$ mod $q$ and if it is $-1$ then $\operatorname{tr} (x^e)=0$ mod $q$ so it suffices to show that $\frac{ x^e}{ \overline{x^e}}$ isusual formula for the quadratic residue, but we have gives (mod $q$)
$$\left( \frac{ \operatorname{Norm}(x)}{q} \right) = \left( \frac{ x\overline{x}}{q} \right) = x^{ \frac{q-1}{2}} {\overline{x}}^{\frac{q-1}{2}} $$ and the ratio between these is$$\left( \frac{ \operatorname{Norm}(x)}{q} \right) = \left( \frac{ x\overline{x}}{q} \right) = x^{ \frac{q-1}{2}} {\overline{x}}^{\frac{q-1}{2}} = x^{ \frac{q-1}{2}} {\overline{x}}^{\frac{q-1}{2}} \cdot \frac{ \operatorname{Frob}_q(x)}{x^q} =\begin{cases} x^{ - \frac{q-1}{2}} \overline{x}^{\frac{q-1}{2}} & \textrm{if }q\textrm{ split} \\ x^{ - \frac{q+1}{2}} \overline{x}^{\frac{q+1}{2}} & \textrm{if }q\textrm{ inert} \end{cases}$$ $x^{ \frac{q-1}{2}-e} {\overline{x}}^{ \frac{q-1}{2} +e }$.$$ = \frac{ \overline{x}^e}{ x^e} = \frac{ \overline{x^e}}{x^e}.$$
Here is the only place I have to split into cases. If $q$ is split then the ratioquadratic residue symbol is $\overline{x}^{q-1}$ but $(\mathcal O_K/q)^* = \mathbb F_q^* \times \mathbb F_q^*$ has exponent$1$ this gives $q-1$ so the ratio is$\overline{x^e}=x^e$ $1$. If(mod $q$ is nonsplit then), so $x^e \in \mathbb Z + q \mathcal O_K$, while if the ratioquadratic residue symbol is $x^{-1} \overline{x}^q$ but$-1$ his gives $\overline{x}^q = x^{-1}$$\overline{x^e}=-x^e$ (mod $q$), so the ratio is $1$$\operatorname{tr}(x^e) = x^e + \overline{x^e}=0$ mod $q$.
The proof should probably clarify a little more what's going on here.