Given a set of sequences, compute a corresponding set of functions Consider the following set of sequences:
$
 S_k(n)=
 \begin{cases}
  1 & \text{$n    \equiv0\pmod{k}$}\\
  0 & \text{$n\not\equiv0\pmod{k}$}\\
 \end{cases}
$
I want to compute a set of functions $f_k:\mathbb{R}\rightarrow\mathbb{R}$ such that:


*

*$\forall{n}\in\mathbb{N}:f_k(n)=S_k(n)$

*$f_k(x)$ is continuous in the entire domain

*$f_k(x)$ is infinitely differentiable in the entire domain



It's pretty easy for $k=1$:
$f_1(x)=\dfrac{\sin(\frac{4x+1}{2}\pi)+1}{2}$


It's pretty easy for $k=2$:
$f_2(x)=\dfrac{\sin(\frac{2x+1}{2}\pi)+1}{2}$


Intuitively, it looks feasible for $k=3$ using the same technique, though I'm not quite sure how.
It doesn't look feasible for any $k>3$ using the same technique, so I'm looking for alternatives.
Any ideas will be be highly appreciated.
 A: Update: The following formula works for all $k\ge 2$ and was obtained after looking at several examples discussed below; I thought I'd put it at the top for convenience of anyone reading this answer.
$$f_k(x)=\frac1k \sum_{j=0}^{k-1}\cos \frac{2\pi j x}{k}.$$
Each term is periodic mod $k$ so the sum is also. $f_k(0)=1$ since each cosine summed is $1$ and there are $k$ terms, so the initial factor of $(1/k)$ gives $1$ for the function value. Now for $x$ an integer with $1 \le x \le k-1$ we note that the summed cosines are real parts of the associated exponential terms, which are the powers of $e^{2\pi i x/k}$ (from the zero power up to the $k-1$ power). The base here is not $1$ so that the formula for the sum of a finite geometric series applies, and the result is 
$$\frac{e^{2\pi i x}-1}{e^{2\pi i x/k}-1},$$ which is zero because the numerator is zero($x$ here is an integer between $1$ and $k-1$). Hence $f_k(x)=0$ for integers $x$ not divisible by $k$ as required.
[the following is previous version/ideas]
For $k=3$ take $$f(x)=\frac23\cos\frac{2\pi x}{3}+\frac13.$$
This was a rescaling of the fact that the cosines of multiples of $2\pi/3$ starting at the zero multiple go $1,-1/2,-1/2,1,-1/2,-1/2 \cdots.$ Offhand I don't see a similar trick for larger $k$ since the sequence of cosines of multiples of $2\pi/k$ have more than two values. There might be a way to combine some to give offsets and achieve higher $k$ formulas, however
For $k=4$ take $$f_4(x)=\frac12(\cos \frac{\pi x}{2}+\frac{\cos(\pi x)+1)}{2}).$$
This works by combining the pattern of cosines of multiples of cosines of $\pi/2$ namely $1,0,-1,0,1,0,-1,0,\cdots$ with the values of an alternate formula for $f_2(x)$ namely the second displayed term, and taking their average. At any rate it shows we can go beyond $k=3$ without getting too involved.
In fact, one can multiply the solutions $f_2$ and $f_3$ to get a formula which works as $f_6.$ Such multiplications would seem to work as long as the two subscripts involved are coprime. I checked this and $f_4\cdot f_3$ works as an example of an $f_{12}.$
ADDED: a way to get an $f_p$ for any odd prime $p$:
Define $$h(x,p)=\cos \frac{2\pi x}{p}$$ and also
$$g(x,p)=\sum_{x=0}^{(p-1)/2} h(k \cdot x,p). \tag{*}$$
Then because of what taking multiples of the angles does to the cosines, the sum will cause all except the multiples of $p$ to have the same value. Then one can adjust this $h$ by a linear transform to get a suitable $f_p.$ That is, the values of $h(0),h(1),...$ will give a periodic sequence of the form $a,b,b,...,b,a,b,b,...,b,...$ having period $p$ which may then be adjusted. For example with $p=7$ I get $a=4$ and $b=1/2$ so that mod 7 the sequence so far goes $4,1/2,1/2,1/2,1/2,1/2,1/2,4,...$ with period 7. 
This is in a way only a "theory" solution since in general one will not have simple closed forms for the values of the cosine sums.
A final simplification: If in formula $(*)$ we replace the upper summation limit by $p-1$ and initially multiply the sum by $(1/p)$, then the result already works (without need for further adjustment) to give an $f_k$ when $k$ is the odd prime $p$.
