Repunit (source code)
= Repunit
{title2=$R_b(k)$}
{wiki}
In a <positional notation> of integer <radix> $b\ge2$, a <repunit> is a <repdigit> whose <numerical digits> are all $1$. A length-$k$ <repunit>, with $k\ge1$, is the <geometric series>
$$
R_b(k)=1+b+\cdots+b^{k-1}=\frac{b^k-1}{b-1}.
$$
For example, $R_{10}(4)=1111$, while $R_2(4)=(1111)_2=15$. The same string has different values in different radices.
Appending one <numerical digit> gives $R_b(k+1)=bR_b(k)+1$. Thus <remainders> <modulo> a <positive integer> $n$ obey $r_{k+1}=(br_k+1)\bmod n$, starting with $r_0=0$. This <recurrence relation> avoids constructing huge <integers>. For decimal <repunits> <modulo> $7$, the successive <remainders> are $1,4,6,5,2,0$; hence the six-digit <repunit> is divisible by $7$.
A <repunit> divisible by $n$ exists exactly when $b,n$ are <coprime integers>, and one then exists with at most $n$ digits. Necessity follows because a common <prime factor> of $b,n$ divides every nonconstant term of $R_b(k)$, leaving remainder one. For sufficiency, examine $R_b(1),\ldots,R_b(n)$ <modulo> $n$. If none is zero, the <pigeonhole principle> gives equal <remainders> at two indices $i>j$. Their difference is $b^jR_b(i-j)$. Cancelling the invertible factor $b^j$ <modulo> $n$ produces a divisible <repunit> of length $i-j\le n$.
Back to article page