# Decimal expansions and Prime numbers

## Introduction⌗

In today’s rather small blog post, I’d like to tackle a issue/curiosity that popped up while discussing decimal arbitrary precision arithmetic.

How to determine when the decimal expansion is infinite?

While the question is interesting on its own, there are many other intriguing questions (how long will the decimal expansion be?) not answered in this blog post and left for the reader to answer (after, hopefully, a spark of inspiration stemming from reading this tiny blog post - feel free to share your observations in the comments below).

## Proof⌗

Consider a rational number $\frac{a}{b}$, where $a,b \in \mathcal{Z}$, $a \neq b$ and $\gcd(a,b)=1$ (important, since this implies that it’s impossible to cancel out the factors of a and b, since they are coprime). Said rational can be expressed as such:

$$ \frac{a}{b} = a \times \prod_{p \in P} \frac{1}{p} $$

Where $P$ is the prime factorisation of the denominator, $b$. The $a$ factor doesn’t play a role in determining whether the decimal expansion of the expression on the right hand side is terminating, so the rest of the proof focuses mainly on the product.

Important observation, given $b$ as an arbitrary prime number:

$$ \neg \mathop{\exists}_{k \in \mathcal{Z}} \gcd(10k, b) = 1 \iff \frac{1}{b}\ \textrm{has a non-terminating decimal expansion} $$

What stems from it is that only $\frac{1}{2}$ and $\frac{1}{5}$ have terminating decimal expansions, since 5 and 2 are prime factors of 10. Furthermore, for all prime numbers not equal to 2 and 5, $\frac{1}{p}$ has a non-terminating decimal expansion. The reasoning is quite simple - $b$ can not be a multiple of $10k$ due to the canonical prime number definition. The only other case in which $\gcd(10k, b) \neq 1$ could be true is when $b$ was a prime factor of $10k$, in which case it’s only $b=2$ and $b=5$.

Going back to to the first equality presented, it is sufficient that there exists a prime factor other than 2 or 5 in the product expansion for the rational’s decimal expansion to be infinite.