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.

  • $\begingroup$ 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. $\endgroup$
    – JWT
    Commented Jul 19, 2022 at 19:00
  • 1
    $\begingroup$ Relevant links: math.stackexchange.com/q/51762/1072645, math.stackexchange.com/q/1422895/1072645 $\endgroup$
    – user80184
    Commented Jul 19, 2022 at 19:13
  • $\begingroup$ Why would anyone downvote this?! If someone doesn't understand a puzzle they haven't even left the locker room. $\endgroup$
    – humn
    Commented Jul 20, 2022 at 19:49
  • 1
    $\begingroup$ @rotta I didn't downvote, but I speculate that others may have felt this question has already been asked before (see above links). $\endgroup$
    – user80184
    Commented Jul 20, 2022 at 20:23
  • $\begingroup$ As such, @BeKind, thank you for commenting with relevant comparisons. It serves better than any vote. $\endgroup$
    – humn
    Commented Jul 20, 2022 at 21:18

1 Answer 1


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}$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.