0
$\begingroup$

For the period of something like $1/d$ where $d$ is a positive integer, I saw an algorithm repeatedly doing:

$\begin{align*}r &= 1\\ r &= 10r \bmod d \quad\text{ (until } r = 1) \end{align*}$

and the number of steps was the period.

  • 0
    Ah yes I had it wrong but it was just long division.2012-05-27

1 Answers 1

4

This is just long division. Once you reach the end you take the remainder over, put a zero next to it and repeat the process, eg:

$ 2/5 = (2.0)/5 = 0.4 $

So in this case since we are doing $1/d$ we start with one. How many times this process is repeated is just how many times we carried the remainder over which is the length of the decimal.

  • 0
    Ah you're exactly right.2012-05-27