TITLE: Formula for the sequence repeating twice each power of $2$
QUESTION [7 upvotes]: I am working on some project that needs to calculate what $a_n$ element of the set of numbers $$1, 1, 2, 2, 4, 4, 8, 8, 16, 16 \ldots$$ will be.
$n$ can be quite big number so for performance issues I have to calculate formula for this set of numbers (Note: first element may be different). What I've done so far is that I managed to find out how to calculate next element using element before. My formula for this is: 
$$a_n = a_{n-1}\cdot 2^{\frac{1 + (-1)^{n-1}}2}$$
Now from this I want to calculate $a_n$ element using $a_1$ element. with this I am stuck.

REPLY [2 votes]: In addition to the other more correct answers, it is interesting to note that this sequence can be generated with only two bit shifts:
$${\tt{}a_n=1 << (n >> 1)}$$
Note that ${\tt{}n}\in[0,\infty]$, not ${\tt{}n}\in[1,\infty]$. Also, if you allow $\tt{}1$ to vary (for example, choose $\tt{}a_{n,\alpha}=\alpha << (n >> \alpha)$), you get sequences like this:
$\alpha=1: \quad 1, 1, 2, 2, 4, 4, 8, 8, 16, 16, \cdots$
$\alpha=2: \quad 2, 2, 2, 2, 4, 4, 4, 4, 8, 8, \cdots$
$\alpha=2: \quad 3, 3, 3, 3, 3, 3, 3, 3, 6, 6, \cdots$