Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
The period is the smallest positive $k$ such that $10^k\equiv 1\pmod{d}$. Of course we must put restrictions on $d$. Assume that neither $2$ nor $5$ divides $d$. – André Nicolas May 26 '12 at 22:17
It does not work for $d=6$ – Henry May 26 '12 at 22:20
Ah yes I had it wrong but it was just long division. – Palace Chan May 27 '12 at 1:00
up vote 4 down vote accepted

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.

share|cite|improve this answer
Ah you're exactly right. – Palace Chan May 27 '12 at 0:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.