# Function that is 0 for all positive integers divisible by x and 1 otherwise

I am working on dice probabilities and I need a function where every xth item of the set of positive integers > 0 (n) is 0 and 1 otherwise.* x is also a positive integers.

So, can you, without the use of indicator functions, find an elementary function that satisfies

$$f(n,x)= \begin{cases} 0 &\text{if n \bmod x = 0},\\ 1 &\text{if n \bmod x > 0} \end{cases}$$

I am trying to model a die roll where if you roll a max on the dice, you roll again and add the new roll. This is recursive, so long as you keep rolling the max amount on each roll. x, i the dice type (d4, d6, etc) and n is the number you want to roll. The probabilities are fairly simple except for the case there you roll max die. Under this system it is impossible to get a total roll of 6 on a d6, because you immediately roll the dice and add the new number.

Similar, to this question. But slightly more generalized. But it is trying to introduce a periodic function, similar to what I need.

* Obviously the inverse would work as well since 1- f(x) will flip the bit.

• Not for an elementary function, no. I went down that route, and it does give a solution, the problem come when you try to do s summation.
– JWT
Jul 19, 2022 at 19:00
• – user80184
Jul 19, 2022 at 19:13
• Why would anyone downvote this?! If someone doesn't understand a puzzle they haven't even left the locker room.
– humn
Jul 20, 2022 at 19:49
• @rotta I didn't downvote, but I speculate that others may have felt this question has already been asked before (see above links).
– user80184
Jul 20, 2022 at 20:23
• As such, @BeKind, thank you for commenting with relevant comparisons. It serves better than any vote.
– humn
Jul 20, 2022 at 21:18

Let $$\omega=\exp(2\pi i/x)$$ be the primitive $$x$$th root of unity. Note that $$\frac{1+\omega^n+\omega^{2n}+\dots+\omega^{(x-1)n}}{x}=\begin{cases}1&\text{if x \mid n}\\0&\text{otherwise}\end{cases}$$ So your desired function is $$1-\frac{1+\omega^n+\omega^{2n}+\dots+\omega^{(x-1)n}}{x}$$ For example, $$x=2$$ yields $$1-\frac{1+\omega^n}{2}=1-\frac{1+(-1)^n}{2}=\frac{1-(-1)^n}{2}$$