I am considering a problem concerning Cantor set.

Let $p>3$ be a prime.

Is there a way to caculate the number of $1$ in the ternary expansion of $a_p=\frac{3^{p-1}-1}{p}$ or just to decide whether $1$ appears in the ternary expansion?

Any result related to this quesion is also welcome.


1 Answer 1


This is not a full answer, but let me point out that there is an explicitlish formula for the ternary expansion of such numbers, for any given value of $3$.

For integers $a$ and $m>0$, let $a\bmod m$ denote $a-m\lfloor a/m\rfloor$ (the unique residue in $\{0,\dots,m-1\}$ congruent to $a$ modulo $m$). Inside the left argument of this operator, $a^{-1}$ denotes multiplicative inverse of $a$ modulo $m$.

Proposition: Let $b,m,n\in\mathbb N$, where $m>1$ and $\gcd(b,m)=1$. Then $$\def\FL{\genfrac\lfloor\rfloor{}{}}\FL{b^n}m=\sum_{i<n}b^i\bigl((-m^{-1}(b^{n-i}\bmod m))\bmod b\bigr).$$

Proof: Using a telescoping sum, $$\begin{align*} \FL{b^n}m &=\sum_{i<n}b^i\left(\FL{b^{n-i}}m-b\FL{b^{n-i-1}}m\right)\\ &=\sum_{i<n}b^i\left(\frac{b^{n-i}-(b^{n-i}\bmod m)}m-\frac{b^{n-i}-b(b^{n-i-1}\bmod m)}m\right)\\ &=\sum_{i<n}b^i\left(\frac{b(b^{n-i-1}\bmod m)-(b^{n-i}\bmod m)}m\right). \end{align*}$$ Now, if we put $u=(b^{n-i-1}\bmod m)$ and $v=(b^{n-i}\bmod m)$, then $v=(bu\bmod m)$; that is, $bu-v=mr$, where $r=\lfloor bu/m\rfloor$ is the unique element of $\{0,\dots,b-1\}$ such that $b\mid v+mr$. In other words, $r$ is $(-m^{-1}v)\bmod b$. QED

Corollary: If $p\equiv\pm1\pmod 3$ is prime, then $$\frac{3^{p-1}-1}p=\sum_{i<p-1}3^i\bigl((\mp(3^{p-1-i}\bmod p))\bmod 3\bigr).$$

This allows to answer some questions about the distribution of ternary digits in this number, for example:

  • If $p\equiv2\pmod3$, then digit $1$ appears at position $0$.

  • If $3$ is a primitive root modulo $p$, then $\{3^{p-1-i}\bmod p:i<p-1\}=\{1,\dots,p-1\}$, thus digit $1$ appears $(p\mp1)/3$ many times.

It’s tempting to think that “roughly $1/3$” of the digits should be $1$ in any case, but in the extreme example $p=3^k-1$ (which can’t be prime, though), digit $1$ has frequency $1/k$ and digit $2$ does not appear at all.

  • 2
    $\begingroup$ Just to get some intuition I've done a small statistic for the frequencies of digits when $3 \lt p \lt 9999 \in \mathbb P$. Don't know whether such a list might be interesting here. Perhaps special interesting cases are $p\in \{13,757,1093\}$ (missing digit "1") $p=5$ (missing digit "0") and $p=3851$ (having extreme(?) form of periodic pattern). I hoped that perhaps a statistic like "chi-square" over the frequencies of digits is interesting, but couldn't nail anything down from this statistic. $\endgroup$ Aug 15, 2023 at 13:45

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.