How to write a function to express "not divisible by 2 and 3"? Is there equation that gives numbers that are not divisible by $2$ nor by $3$ (as a function of $n$).
$$f(1)=5,\; f(2)=7,\; f(3)=11,\; f(4)=13,\; f(5)=17,\; \ldots $$
Wolfram alpha gives it as:
$$f(n)=\frac12(-1)^n\left(\,6n(-1)^n+3(-1)^n-1\,\right)$$
But not sure if it can be expanded into numbers not divisible by $2$, $3$, $5$. And the result looks increasingly complicated the more there is requirements for divisibility.
 A: It does get more complicated, and very quickly. This is sort of the essence of what makes primes and combinatorics so hard to work with.
There are lots of ways one could write this, but one of the easiest to understand is probably $$30k \pm \{1,7,11,13\}.$$
For every integer $k$, meaning every multiple of $30$, adding or subtracting those four numbers as you go will cover every number not divisible by $5$ or less. This is because $30=5\#=2\times 3\times 5 \pm r$ will always be coprime to $30$ if $r$ is coprime to $30$ (and thus, coprime to $2,3,5$.) In every periodic cycle of $30$, there are only eight coprime choices: $\{1,7,11,13,17,19,23,29\}$, all prime themselves (and $1$).
This general approach can be carried as far as you like, but it becomes untenable to do it by brute force; out of the $2\times3\times5\times7=210$ numbers forming the next larger primorial period, there are $\varphi(210)=48$ coprime terms, the rest containing a $7$ or lower. (Google primorials and/or Euler's totient function for more on this sort of stuff.)
To your original question, there are multiple ways you could write it, e.g. the comment someone gave above. Thus it's hard to answer without knowing your motivation or at least sense of aesthetics.
Also, Mathematica/Alpha like to give you $(-1)^x$ type terms, but it's worth noting that these are directly interchangeable with things like floor/ceiling functions, taking values $\bmod 2$, and piecewise/conditional function definitions. Among other things, each of those will let you calculate subexpressions conditional on parity, which means there's typically a lot of nuanced and potentially irreducible complexity going on.
