Some formulae for a periodic sequence $-1,-1,1,1...$? Some formulae  for a periodic sequence?

when $T = 2$, we have $-1,1,-1,1,-1,1,\text{...}$, the formula is 
$$\begin{align*}(-1)^n\end{align*}$$
when $T = 4$, we have $-1,-1,1,1,-1,-1,1,1\text{...}$, the formula is?
And how about the case $T=k$?
 A: The clearest is $a_n=-1$ if $n$ leaves remainder $1$ or $2$ on division by $4$, and $a_n=1$ otherwise. 
There are also conventionally "closed form" formulas, such as 
$$a_n=\sqrt{2}\cos\left(\frac{(2n+1)\pi}{4}\right).$$
A: 
Use discrete Fourier transform.

It is a general fact that every periodic sequence $(x_n)$ of period $T$ is in the linear span of the sequences $\{e^T_k\,;\,1\leqslant k\leqslant T\}$, where, for every $n$,
$$
(e_k^T)_n=\mathrm e^{2\mathrm i \pi nk/T}.
$$
That is, there exists $(a_k)_{1\leqslant k\leqslant T}$ such that, for every $n$,
$$
x_n=\sum_{k=1}^Ta_k(e_k^T)_n=\sum_{k=1}^Ta_k\mathrm e^{2\mathrm i \pi nk/T}.
$$
To find $(a_k)_{1\leqslant k\leqslant T}$, one considers the equations above over one period, say for $1\leqslant n\leqslant T$, as a Cràmer system with unknowns $(a_k)_{1\leqslant k\leqslant T}$.

Example: Consider some sequence $x=(x_1,x_2,x_3,x_1,x_2,x_3,\ldots)$, then $T=3$, 
$$
e_1^3=(j,j^2,1,j,j^2,1,\ldots),\quad e^3_2=(j^2,j,1,j^2,j,1,\ldots),\qquad e^3_3=(1,1,1,1,1,1,\ldots),
$$ 
with $j=\mathrm e^{2\mathrm i\pi/3}$, and one looks for $(a_1,a_2,a_3)$ such that $x=a_1e^3_1+a_2e^3_2+a_3e^3_3$, that is,
$$
x_1=a_1j+a_2j^2+a_3,\quad x_2=a_1j^2+a_2j+a_3,\quad x_3=a_1+a_2+a_3.
$$ 
Thus,
$$
3a_1=j^2x_1+jx_2+x_3,\quad 3a_2=jx_1+j^2x_2+x_3,\quad 3a_3=x_1+x_2+x_3,
$$
which yields $x_n$ as a linear combination of $j^n$, $j^{2n}$ and $1$, namely, for every $n$,
$$
x_n=a_1j^n+a_2j^{2n}+a_3.
$$
A: You can write it as $(-1)^{\large \lfloor \frac{2 \cdot n+T-2}{T} \rfloor}$.
If you defined things a bit differently (start counting from zero, parameterize the half period instead of the full period) you could just write $(-1)^{\large \lfloor \frac{n}{T} \rfloor}$.
