# Number of $1$'s in the ternary expansion of $a_p=\frac{3^{p-1}-1}{p}$

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.

• Question simulposted to m.se, math.stackexchange.com/questions/4741400/… Jul 24, 2023 at 4:13
• Just an isolated finding: in the set of $3^{p-1}$ numbers between $0$ and $3^{p-1}-1$ there are only $2^{p-1}$ numbers having ternary digits representation without digit $1$ - - - - - - additionally: Noticing 2 upvotes at my recent comment- for those interested: sketchpad collecting current low level heuristics: go.helms-net.de/math/expdioph/DigitsDistributionIn_3hochN.pdf . (Has not yet character of an answer...) Aug 17, 2023 at 3:43

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

Proof: Using a telescoping sum, \begin{align*} \FL{b^n}m &=\sum_{i 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

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, 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.

• 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. Aug 15, 2023 at 13:45