Find period of reciprocal $1$/$x$? [duplicate]

Possible Duplicate:
Compute the period of a decimal number a priori

How to find the period of a reciprocal $1$/$x$ ? in both cases when it is terminating i.e (the distinct prime factors of the denominator are only 2's and 5's ) and when it keeps repeating immediately as in $1$/$7$ or after some digits as in $1$/$6$

-

marked as duplicate by Gerry Myerson, Sasha, Ross Millikan, Old John, t.b.Aug 29 '12 at 23:40

This question was marked as an exact duplicate of an existing question.

You find the period of the reciprocal by doing the division until it starts repeating. One can express this in terms of finding the smallest solution to $10^r\equiv10^s\pmod x$, but it's basically the same thing/ – Gerry Myerson Aug 29 '12 at 13:07

Using this, we can figure out $\lambda(x)$, for any given $x$ such that $(x,10)=1$

So, $10^{\lambda(x)}≡1\pmod x\implies x\mid(10^{\lambda(x)}-1)$

Let $d$ the smallest positive integer such that $10^d≡1\pmod x$

Also let $\lambda(x)=de+g$ where $0≤g<d$

$a^g=a^{\lambda(x)-de}=a^{\lambda(x)}-(a^d)^e≡1\pmod x$, but $d$ is the smallest positive integer.

So, $g=0\implies d\mid \lambda(x)$, $d$ is called $ord_x{10}$.

Then we need to find out this $d$ .

Let $x\cdot t=10^d-1$ where t is a natural number so, $\frac{1}{x}=\frac{t}{10^d-1}$ and d will be period.

For the divisors of $10$, i.e, $2,5$ the minimum power of $10$ that is divisible by $2^m\cdot 5^n$ is $max(m,n)$ where m,n are non-negative integers.

So, the length of $\frac{1}{2^m\cdot 5^n}$ will be $max(m,n)$.

If $x=2^m\cdot 5^n \cdot Q$ where $(Q,10)=1$,

$\frac{1}{x}$ will have $max(m,n)$ non-recurring digits followed by $d$ recurring digits where d is $ord_x{10}$.

-