Consider sum: \begin{equation} S_q(n) = \sum_{x=1}^{n}\Big\{ \frac{x^q}{n} \Big\} \end{equation} where $\{x\}$ is fractional part of $x$. It's easy to see that $S_{1}(n) = \frac{1}{2}(n-1)$, but already $S_{2}(n)$ looks more complicated. I have some observations about the $S_q(n),\; q > 1$. It is likely that they are false, since I have no proof, but it is still interesting to ask about it here.

**Observation 1:**
If an integer $n = p_{1}^{q_1}\ldots p_{m}^{q_m}$, where $p_i$ are prime numbers of the form $4k+1$, then
holds:
\begin{equation}\label{eq1}
S_{2}(n) = \frac{1}{2}\Big(n- p_{1}^{\big\lfloor \frac{q_1}{2} \big\rfloor}\ldots p_{m}^{\big\lfloor \frac{q_m}{2} \big\rfloor}\Big)
\end{equation}

**Observation 2:**
If an integer $n = p_{1}^{q_1}\ldots p_{m}^{q_m}$, where $p_i$ are prime numbers, then for odd $q > 1$ holds:
\begin{equation}\label{eq2}
S_{q}(n) = \frac{1}{2}\Big(n- p_{1}^{\big\lfloor
\frac{1}{2}\big\lfloor q_1 - \frac{2q_1}{q} \big\rfloor + \frac{q_1}{2}
\big\rfloor}\ldots p_{m}^{\big\lfloor
\frac{1}{2}\big\lfloor q_m - \frac{2q_m}{q} \big\rfloor + \frac{q_m}{2}
\big\rfloor}\Big)
\end{equation}

I couldn't find any pattern for $S_{2q}(n)$ in general, only some special cases:

\begin{equation} S_{2}(2^k) = \frac{1}{2}(2^k - a_{k+1}) = \frac{1}{2}(2^k-b_{k}) \end{equation} where $a_k$ is the sequence A060482, $k>1$ and $b_k$ is the sequence A136252, $k > 0$.

\begin{equation} S_{2}(3^k) = \frac{1}{2}\Big(3^k - \frac{a_{k+2}}{3}\Big) \end{equation} where $a_k$ is the sequence A060647, $k>0$

\begin{equation} S_{2}(4^k) = \frac{1}{2}(4^k - a_{k+1}) \end{equation} where $a_k$ is the sequence A068156, $k>0$

\begin{equation} S_{4}(2^k) = \frac{1}{2}\Big(2^k - a_{\big\lfloor \frac{k-1}{4} \big\rfloor + 1}\Big) \end{equation} where $a_k$ is the sequence A000225, $k > 0$

**Question:**

Are the formulas in observations 1,2 correct? If the formulas are correct, is there any general pattern for $S_{2q}(n)$?

*The code for numerical validation of certain small values*