# Recurring Decimal Expansion

For any natural number $$n>1$$, we write the infinite decimal expansion of $$\frac 1n$$ (for example, $$\frac 14$$ is written as $$0.24999$$... instead of $$0.25$$). We need to determine the length of the non-periodic part of the infinite decimal expansion of $$\frac 1n$$.

I tried many methods, a somewhat promising one was to assume $$\frac 1n$$ to be some $$0.abbbbb$$..., where ‘$$a$$’ denotes the non-recurring part which has $$r$$ digits including zero, while ‘$$b$$’ is the recurring part. But I get stuck at deciding the lower and upper bounds for $$r$$. Please help.

(Please note: this is my first post on this website. So if I have to improve the way I should post the question in, please let me know how to correct the errors in my post. Thanks.)

• Leading question: can you prove that if $n$ is divisible by neither $2$ nor $5$, then the decimal fraction is immediately periodic (that is, the length of the non-periodic part is $0$)? (By the way, the standard name for that part is the "pre-periodic" part.) – Greg Martin Dec 31 '18 at 18:51
• Take the examples of $\frac{1}{3}=0.3333333...$, f $\frac{1}{7}=0.142857142857...$, and $\frac{1}{11}=0.09090909090909...$. If $n$ is not divisible by $2$ or $5$, the pre-periodic length will always be zero. – poetasis Dec 31 '18 at 19:33
• @GregMartin, It actually seemed intuitive for me, but I’m not able to come up with a rigorous proof for that. (Well, actually, every step of the solution seems very intuitive, but I don’t know how to write a rigorous solution by giving proofs for them :/ ) – Yellow Jan 1 '19 at 3:50
• By the way, is there any way I can rigorously prove that the the length of the pre-periodic part is related to powers of $2$ and $5$? Because, if powers of any other prime are not going to affect the length of the pre- periodic part, then powers of $2$ or $5$ might have some relation with its length, right? – Yellow Jan 1 '19 at 15:30
• Yes, the length of the pre-periodic part is definitely going to be determined by the powers of $2$ and $5$! Do you know modular arithmetic? Do you know what the "order of $a$ modulo $n$" is? Because knowing that the period of $1/n$ is actually equal to the order of $10$ modulo $n$ (when $n$ is not divisible by $2$ or $5$) makes the periodicity easier to prove. – Greg Martin Jan 1 '19 at 20:01

Lemma:

For every number $$n\in N$$ that is not divisible by 2 and 5, there exists $$k\in N$$ such that $$n\mid10^k-1$$

Proof: Suppose that the statement is not true, i.e. $$10^k-1\not\equiv0 \pmod n$$ for all values of $$k$$. There are infinitely many values of $$k$$ and just $$n-1$$ possible values ($$1\dots n-1$$) for $$10^k-1\pmod n$$. So by pidgeon hole principle there are two different values $$k_1, k_2$$ such that:

$$10^{k_1}-1\equiv10^{k_2}-1\pmod n,\quad (k_1>k_2)$$

This simply means that:

$$10^{k_1}-10^{k_2}\equiv0\pmod n$$

$$10^{k_2}(10^{k1-k2}-1)\equiv0\pmod n$$

Number $$n$$ has no factors 2 and 5 so obviously $$n\nmid 10^{k_2}$$ which implies that $$n\mid(10^{k_1-k_2}-1)$$ or:

$$n\mid10^k-1$$

...where $$k=k_1-k_2$$.

End of lemma proof.

Part 1:

Let us now show that:

For every number $$n$$ such that $$2\nmid n$$ and $$5\nmid n$$, decimal representation of $$1/n$$ has no pre-periodic part. In other words, $$1/n$$ can be written as: $$\frac 1n=0.aaa\dots=0.\bar{a}\tag{1}$$

...where $$a$$ stands for a group of repeating digits (possibly starting with zero) of length $$l_a$$. For example for $$n=7$$: $$1/7=0.\overline{142857}$$, so $$a=142857$$ and $$l_a=6$$.

One can easily show that (1) can be rewritten in the following way:

$${\frac1n}=\frac{a}{10^{l_a}-1}$$

$$a=\frac{10^{l_a}-1}{n}$$

According to our lemma, it's guaranted that there exists $$l_a$$ such that $$n\mid 10^{l_a}-1$$ so it's is possible to find $$a$$ for every $$n$$ such that $$1/n=0.\bar{a}$$, without a pre-periodic part.

Part 2

If $$2\mid n$$ or $$5\mid n$$, decimal representation of $$1/n$$ has a pre-periodic part: $$\frac1n=0.b\overline {a}\tag{2}$$

...with the lenght of pre-periodic group of digits $$b$$ equal to $$l_b$$ and length of periodic group of digits $$a$$ equal to $$l_a$$.

Suppose the pposite, that there is some number $$n$$ divisible by either 2 or 5 such that:

$$\frac1n=0.\bar{a}=\frac{a}{10^{l_a}-1}$$

$$na=10^{l_a}-1$$

...which is impossible because the LHS is divisible by 2 or 5 and the RHS is clearly not.

Based on part 1 and 2 we now know that:

Decimal representation of $$1/n$$ has pre-periodic part if and only if $$2\mid n$$ or $$5\mid n$$.

Part 3

For a number $$n$$ of the form $$n=2^p5^qm$$ and $$2,5\nmid m$$ the length of pre-periodic part is exactly $$\max(p,q)$$.

It can be easily proved that any number of the form $$0.b\bar{a}$$ can be written as:

$$0.b\bar{a}=\frac{b}{10^{l_b}}+\frac{a}{10^{l_b}(10^{l_a}-1)}\tag{3}$$

Because $$m$$ is not divisible by 2 or 5, we can write $$1/m$$ as:

$$\frac1m=\frac{a}{10^{l_a}-1}$$

which means that:

$$\frac1n=\frac1{2^p5^q} \cdot \frac1m$$

If we introduce:

$$r=\max(p,q)$$

we get:

$$\frac1n=\frac{2^{r-p}5^{r-q}}{10^r} \cdot \frac1m=\frac{2^{r-p}5^{r-q}a}{10^r(10^{l_a}-1)}\tag{4}$$

Now look at (4) carefully.

Case 1:

$$2^{r-p}5^{r-q}a<10^{l_a}-1$$

By comparing (3) and (4), the length of pre-periodic part is $$r$$, and the pre-periodic part is made of zeroes $$b=0$$. Periodic part is equal to $$2^{r-p}5^{r-q}a$$ and the length of the periodic part is $$l_a$$.

Case 2:

$$2^{r-p}5^{r-q}a>10^{l_a}-1$$

In that case you can write:

$$2^{r-p}5^{r-q}a=s(10^{l_a}-1)+a_1$$

...and (4) becomes:

$$\frac1n=\frac{s(10^{l_a}-1)+a_1}{10^r(10^{l_a}-1)}=\frac{s}{10^r}+\frac{a_1}{10^r(10^{l_a}-1)}$$

By comparing the last expression with (4), the length of the pre-periodic part $$s$$ is again $$r$$ and the length of repeating sequence $$a_1$$ is again $$l_a$$.

Conclusion

1. The length of the periodic part in the decimal representation of $$1/n$$ is determined by the length of periodic part in $$1/m$$ with $$m$$ being the greatest divisor of $$n$$ such that $$2\nmid m$$ and $$5\nmid m$$.
2. Pre-periodic part exists only if $$n$$ is of the form $$2^p5^qm$$.
3. The length of the pre-periodic part is $$\max(p,q)$$

Interesting example

$$\frac{1}{19}=0.\overline{052631578947368421}$$

Periodic part has 18 digits. Now take a look at:

$$\frac{1}{760}=\frac{1}{2^3\cdot5\cdot19}=0.001\overline{315789473684210526}$$

Pre-periodic part has length 3 (because the biggest power of 2 or 5 in $$n=760$$ is 3). And the periodic part has length 18, same length as in $$1/19$$.

• I have a question: Are part $1$ and $2$ really necessary? Because stating that the length of the non-periodic part of $1/n$ if $n = 2^m5^n p$ is $max(m,n)$ also takes care of the situations where $n$ is not at all divisible by $2$ and $5$, in which case $max(m,n)=0$ and so no non-periodic part. – Yellow Jan 7 '19 at 18:52