How to derive $\cos\frac{n\pi}{3}=\frac{1+3(-1)^{[\frac{n+1}{3}]}}{4}$ Consider the following formula to calculate a trigonometric function:  
$$\cos\frac{n\pi}{3}=\frac{1+3(-1)^{[\frac{n+1}{3}]}}{4}$$ $[x]$ denotes the integer part of $x$. The formula is valid for $n=0,2,4,6,...$    
I'm curious how this formula is derived? Is there any analytical method or is it a pure guessing?

HINT:
The  formula can be written as $$\cos\frac{2m\pi}3=\frac{1+3(-1)^{\left[\frac{2m+1}3\right]}}4$$ for all integer $m\ge0$
Now, the value of $(-1)^{\left[\frac{2m+1}3\right]}$ can be $+1,-1$ based on whether $\left[\frac{2m+1}3\right]$ is even or is odd
Observe that the fractional part of $\frac{2m+1}3$ can be $\frac a3$ where $0\le a\le2$
$(1)$ If $\left[\frac{2m+1}3\right]$ is even, the right hand side will be $\frac{1+3}4=1$ 
and $\frac{2m+1}3=2r+\frac a3$ where $r$ is a non-negative integer
So, $2m+1=6r+a\implies a=2(m-3r)+1$ i.e. odd $\implies a=1$
$\implies m=3r\implies $ the Left hand side  $=\cos \frac{2(3r)\pi}3=\cos2r\pi=1$
$(2)$  If $\left[\frac{2m+1}3\right]$ is odd, the right hand side will be $\frac{1-3}4=-\frac12$ 
and $\frac{2m+1}3=2r+1+\frac a3$ where $r$ is a non-negative integer
So, $2m+1=6r+3+a\implies a=2(m-3r-1)$ i.e. even $\implies a=0,2$
$a=0\implies m=3r+1\implies $ the Left hand side becomes $=\cos\frac{2(3r+1)\pi}3=\cos\frac{2\pi}3=\cos\left(\pi-\frac\pi3\right)=-\cos\frac\pi3=-\frac12$ as $\cos(\pi-y)=-\cos y$
$a=2\implies m=3r+2\implies $ the Left hand side becomes $\cos\frac{2(3r+2)\pi}3=\cos\frac{4\pi}3=\cos\left(\pi+\frac\pi3\right)=-\cos\frac\pi3=-\frac12$ as $\cos(\pi+y)=-\cos y$

Alternatively, 
 $m$  can be of the form  $3n,3n+1,3n+2$ where $n$ is any integer
Putting $m=3n,\cos\frac{2m\pi}3=\cos\frac{2(3n)\pi}3=\cos2n\pi=1$
and $\left[\frac{2m+1}3\right]=\left[\frac{2(3n)+1}3\right]=\left[2n+\frac13\right]=2n$
$\implies 1+3(-1)^{\left[\frac{2m+1}3\right]}=1+3(-1)^{2n}=1+3=4$
$\implies \frac{1+3(-1)^{\left[\frac{2m+1}3\right]}}4=1$
Can you take it from here?
