I'm a newbie with number theory and I've been reading this page and trying to figure out how to calculate the length of the digits before the period and digits of the period of a rational number of the form $m/n$.
I came up with the following steps but unfortunately this doesn't always work
- Compute the prime factors for the denominator $n$
- If there are 10-coprimes factors, there's a period otherwise there isn't
- If there's a period, calculate its length taking each 10-coprime factor and doing the discrete logarithm $10^k\equiv 1 \pmod{factor}$ to find the maximum $k \le n$ (i.e. the maximum multiplicative order between the factors)
- There are digits before the period only if the denominator $n$ can be expressed as $n_02^\alpha5^\beta$ (and $n_0$ is coprime to 10) so the length of the digits before the period is the maximum between 0, $\alpha$ and $\beta$
The approach above, however, doesn't work since I'm getting length of 1 for the digits before the period for a simple rational number like $124/6 = 20,\bar6$ (while the result should be 0). I suppose the error should be in step 4.
(5)
in the page I linked – Marco A. Sep 24 '15 at 19:58