<s>[INST] Algebraic Closed Form for $\sum_{n=1}^{k}\left( n- 3 \lfloor \frac{n-1}{3} \rfloor\right)$ Let's look at the following sequence:
$a_n=\left\{1,2,3,1,2,3,1,2,3,1,2,3,...\right\}$
I'm trying to calculate:

$$\sum_{n=1}^{k} a_n$$

Attempts: 
I have a Closed Form for this sequence. 

$$a_n=n- 3 \bigg\lfloor \frac{n-1}{3}  \bigg\rfloor$$

The problem is, I'm looking for a closed form for this summation:

$$\sum_{n=1}^{k}\left( n- 3 \bigg\lfloor \frac{n-1}{3}  \bigg\rfloor\right)$$

Is it possible?
 [/INST] If $n \equiv 0 \pmod{3}$, i.e. say $n=3s$ (where $s \geq 1$), then $a_n=3s-3\lfloor s-\frac{1}{3}\rfloor=3s-3(s-1)=3$. 
If $n \equiv 1 \pmod{3}$, i.e. say $n=3s+1$ (where $s \geq 0$), then $a_n=3s+1-3\lfloor s\rfloor=1$. 
If $n \equiv 2 \pmod{3}$, i.e. say $n=3s+2$ (where $s \geq 0$), then $a_n=3s+2-3\lfloor s+\frac{1}{3}\rfloor=2$.
So depending on what $k$ is we can count the number of terms which are $1's$, $2's$ and $3's$.
For $k=1,2$, the sum will be $\color{red}{1}$ and $\color{red}{3}$, respectively. So for $k \geq 3$, we do the following: 
If $k=3t$ for $t \geq 1$, then
$$\sum_{n=1}^k\left(n-3\left\lfloor n-\frac{1}{3}\right\rfloor\right)=\sum_{n=1}^{3t}\left(n-3\left\lfloor n-\frac{1}{3}\right\rfloor\right)=t(1+2+3)=6t=\color{blue}{2k}.$$
If $k=3t+1$ for $t \geq 1$, then
$$\sum_{n=1}^k\left(n-3\left\lfloor n-\frac{1}{3}\right\rfloor\right)=\sum_{n=1}^{3t+1}\left(n-3\left\lfloor n-\frac{1}{3}\right\rfloor\right)=t(1+2+3)+1=6t+1=\color{blue}{2k-1}.$$
Likewise we can get the expressions for $k=3t+2$ as 
$$\sum_{n=1}^k\left(n-3\left\lfloor n-\frac{1}{3}\right\rfloor\right)=\sum_{n=1}^{3t+2}\left(n-3\left\lfloor n-\frac{1}{3}\right\rfloor\right)=t(1+2+3)+(1+2)=6t+3=\color{blue}{2k-1}.$$
</s>