Finding the general formula of a sequence alternating between even and odd

So I know how to find the general formula of a simple sequence and sequences involving alternating signs but how would you devise a general formula for sequqences alternating between even and odd numbers with different operations occuring to even and odd numbers For example we have the sequence

13, 17, 23, 27, 33, 37...

The sequence starts at 13 and as you can see if the number of the term is odd then we add 4 and if it's even we add 6. I have also devised two separate formula for even and odd numbers. For example if we have to find the 2oth term we use the formula (10n + 7) as 20 is even. If we have to find 21st term we plug it into (10n + 3) as its odd. What I want is a way to devise one general formula for the whole sequence. Is there even a way to do this? Any help would be appreciated. Thanks.

• How about $a_n=10\lceil{n/2}\rceil+7-4(n\bmod2)$? – barak manos Mar 29 '16 at 9:26

Here is an answer using simple arithmetics: $$5\Big(n+\frac{3-(-1)^n}2\Big)+2\cdot(-1)^n$$
• @abdullahaquarius Do you know the exponentiation? $a^n = \underbrace{a\cdot a\cdot\ldots\cdot a}_{n\text{ times}}$. In this case, $(-1)(-1)\ldots(-1)$ is either $1$ or $-1$ depending on $n$. – user326572 Mar 29 '16 at 9:56
Apart the possibilities already suggested (use of $mod$ and use of $(-1)^n$, you can also use the floor function $$f(n) = 6n+7-2\left\lfloor\frac{n}{2}\right\rfloor$$
• @abdullahaquarius I assume you know the floor function. $\lfloor n/2\rfloor$ is equal to $n/2$ if $n$ is even and is equal to $(n-1)/2$ if $n$ is odd. Hence, twice that it is equal to $n$ if $n$ is even and $n-1$ if $n$ is odd. So in practice the formula is $6n+7-n=5n+7$ when $n$ is even, giving the terms $\cdot,17,\cdot,27,\cdots$ and it is equal to $6n+7-(n-1)=5n+6$ when $n$ is odd, giving the terms $13,\cdot,23,\cdot,33,\cdots$. – Giovanni Resta Mar 29 '16 at 9:47