Does a function $f:\mathbb{N}\to\mathbb{N}$ that satisfies $$ f(n) \equiv \begin{cases}0 \bmod{2}, & n\equiv 0,1\bmod{3} \\ 1\bmod{2}, & n\equiv 2\bmod{3} \end{cases} $$ exist (with an explicit formula)? In other words, is there an elementary expression that satisfies the above?
2026-04-01 00:24:34.1775003074
On
Find an integer function $f(n)$ that is even for $n\not \equiv 2\bmod 3$, and odd for $n\equiv 2\bmod 3$
76 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
I'm not quite sure what you are looking for, but the indicator function will meet your requirements. Just take $A=3\mathbb N+2=\{n\in\mathbb N\mid n\equiv 2\bmod 3\}$. Then the function $\mathbf {1}_A:\mathbb N\to \mathbb N$ defined by $$\mathbf 1_A=\begin{cases}0,& n\not\equiv 2\bmod 3\\ 1,& n\equiv 2\bmod 3\end{cases}$$ does the trick already.
explaining the solution through floors
You are looking for the function $f(n)$ of period $3$, which is $1$ for $n = \cdots , - 1,2,5, \cdots $ and null elsewhere (i.e., $f(n) = \left[ {\bmod (n,3) = 2} \right]$ where brackets denote Iverson bracket or the already mentioned $1_{\,A} $function).
Then its sum is clearly $F(n) = \sum\limits_{0\, \le \,k\, \le \,\,n} {f(k)} = \left\lfloor {{{n + 1} \over 3}} \right\rfloor = 1 + \left\lfloor {{{n - 2} \over 3}} \right\rfloor $
and $f(n) = F(n) - F(n - 1) = \left\lfloor {{{n - 2} \over 3}} \right\rfloor - \left\lfloor {{{n - 3} \over 3}} \right\rfloor = \left\lfloor {{{n + 1} \over 3}} \right\rfloor - \left\lfloor {{n \over 3}} \right\rfloor = \cdots $
a solution with cosine
You can also interpolate the "train of pulses" represented by $f(n)$ by $f(x) = {1 \over 3} + {2 \over 3}\cos \left( {{2 \over 3}\pi \left( {x + 1} \right)} \right)$, or by its whole Fourier series if you wish.