Compute $\frac 17$ in $\Bbb{Z}_3.$
We will have to solve $7x\equiv 1\pmod p,~~p=3.$
- We get $x\equiv 1\pmod 3.$
- Then $x\equiv 1+3a_1\pmod 9,$ so $7(1+3a_1)\equiv 1 \pmod 9$ basically lifting the exponent of $p=3,$ we get $1+3a_1\equiv 4\pmod 9\implies a_1\equiv 1\pmod 3.$
- So let $$x\equiv 1+3\cdot 1+3^2\cdot a_2 \pmod 2\implies 7(4+3^2\cdot a_2)\equiv 1\pmod {27}\implies 4+3^2\cdot a_2\equiv 4\pmod {27}\implies a_2\equiv 0 \pmod 3.$$
- So let $$ x\equiv 1+3\cdot 1+3^2\cdot 0+ 3^3\cdot a_3 \pmod {81}\implies 7(4+3^2\cdot 0+3^3\cdot a_3)\equiv 1\pmod {81}\implies 4+3^3\cdot a_3\equiv 58\pmod {81}\implies a_2\equiv 2 \pmod 3.$$
- So let $$ x\equiv 1+3\cdot 1+3^2\cdot 0+ 3^3\cdot 2+3^4\cdot a_4 \pmod {243}\implies 7(4+3^2\cdot 0+3^3\cdot 2+3^4\cdot a_4)\equiv 1\pmod {243}\implies 1+3+54+3^4\cdot a_4\equiv 139\pmod {243}\implies a_4\equiv 1 \pmod 3.$$
- So let $$ x\equiv 1+3\cdot 1+3^2\cdot 0+ 3^3\cdot 2+3^4\cdot 1+ 3^5\cdot a_5 \pmod {729}\implies 7(4+3^2\cdot 0+3^3\cdot 2+3^4\cdot 1+3^5\cdot a_5)\equiv 1\pmod {729}\implies 1+3+54+81\equiv 625\pmod {243}\implies a_5\equiv 2 \pmod 3.$$
I haven't worked out but I think $a_6$ is $0.$
So the sequence we are getting is $(a_0,a_1,a_2,a_3,a_4,\dots)=(1,1,0,2,1,2,\dots).$
But I am not sure if it's correct, since it's not being periodic. Any help?
You are doing correct.
For a slightly more efficient approach, note that $7\mid 3^6-1$ by Fermat's little theorem. Then by noting that $3^6-1=7\cdot104$, we have
\begin{align*} \frac{1}{7} &= -\frac{104}{1 - 3^6} \\ &= -\sum_{n=0}^{\infty}104 \cdot 3^{6n} \\ &= 1 + \sum_{n=0}^{\infty} (3^{6} - 1)3^{6n} - \sum_{n=0}^{\infty}104 \cdot 3^{6n} \\ &= 1 + \sum_{n=0}^{\infty}(3^6-105)3^{6n} \end{align*}
in $\mathbb{Z}_3$, the ring of $3$-adic integers. Then by using $3^6-105 = 212010_{(3)}$, it follows that
$$ \frac{1}{7} = \overline{212010}212011_{(3)} = \overline{021201}1_{(3)}. $$