# Show $\left\lfloor\frac{2n}{p} \right\rfloor - 2 \left\lfloor \frac{n}{p} \right\rfloor \in \{ 0, 1 \}$

I conjecture that $$\left\lfloor\frac{2n}{p} \right\rfloor - 2 \left\lfloor \frac{n}{p} \right\rfloor \in \{ 0, 1 \}.$$ I know that it is always nonnegative, and equals $1$ for $n < p \le 2n$, but the general case for $n$ a natural number and $p$ prime is missing. Any hints?

• Generally, if $x = k+\rho$ with $0 \leqslant \rho < 1$, then $$\lfloor 2x \rfloor - 2\lfloor x\rfloor = \lfloor 2k + 2\rho\rfloor - 2k = \lfloor 2\rho\rfloor.$$ – Daniel Fischer Jun 19 '15 at 21:48
• Yes, that is really simple, thank you! – StefanH Jun 19 '15 at 21:50

By denoting with $\{x\}$ the fractional part of $x$, i.e. $x-\lfloor x\rfloor$, we have: $$f_p(n)=\left\lfloor\frac{2n}{p} \right\rfloor - 2 \left\lfloor \frac{n}{p} \right\rfloor = \left\{\frac{2n}{p}\right\}-2\left\{\frac{n}{p}\right\}$$ where the RHS is trivially a periodic function with period $p$, so $f_p$ just detects if $n\pmod{p}$ is $>\frac{p}{2}$ or not.