0

I wanted to know if there exists a formula or a script that generates the period length for the reciprocal of prime numbers. So for example $\frac17 = 0.142857142857142857$ so a period length of $6$.

I know there is a 10^k mod p but this takes too long for large numbers.

I have seen in this question: Compute the period of a decimal number a priori

@Ross Millikan mentioned that "The period is always a factor of the quotient of the denominator" but I don't know of any literature behind this.

If you know anything about literature on this idea or a formula that can quickly calculate the period length for very large primes, I would be grateful if you can let me know

Update: What I want to know more about is Ross's observation and why couldn't that be used to calculate the repeat digit period for very large numbers? So that's why I asked for literature on this.

Thank you.

Bill Dubuque
  • 272,048
  • 4
    This is just the order of $10$ $\pmod p$. Thus, with $p=101$, for instance, $10$ has order $4$ and $\frac 1{101}=.\overline {0099}$. And $10$ has order $34$ $\pmod {103}$ and $\frac 1{103}=.\overline {0097087378640776699029126213592233}$ is periodic with period $34$. – lulu May 15 '21 at 23:36
  • 2
    Should add: it is not easy to calculate the order of a number modulo a very large prime. If you don't need the exact period, you can always just use $p-1$. It is true that $\frac 1p$ is periodic with period $p-1$ but it may happen that it has a smaller period (which divides $p-1$). If you are able to factor $p-1$ then you can just check each factor. – lulu May 15 '21 at 23:46
  • 1
    Ross's observation comes from Fermat's little theorem. And lulu's is connected to the Carmichael function. – PM 2Ring May 16 '21 at 00:03
  • Please read more carefully. This is already answered in this answer in the thread you linked, which shows how it reduces to an order computation, and links to state-of-the-art literature on such. – Bill Dubuque May 16 '21 at 00:12
  • I expanded the prior mentioned answer. If anything remains unclear then please ask here or there. – Bill Dubuque May 16 '21 at 01:19
  • Thanks for the that, as mentioned in the update of the question, I am really interested to if we know phi(p) is p-1 and phi(p) can be factorised (I assume, please correct me if I am wrong) then why can we not calculate the period? – zakrea2070 May 16 '21 at 01:26
  • Yes, given the prime factorization of some $k$ with $10^k\equiv 1$ (e.q. $k=p-1$) then you can use that to quickly compute the order of $10$ using the Order Test - as I explained in the linked dupe. – Bill Dubuque May 16 '21 at 05:57
  • Sweet, so that means I could calculate the period of 1/p. Do you know of any python library or any other software that could calculate it for very large prime numbers? – zakrea2070 May 16 '21 at 15:34

1 Answers1

0

This has some information about period lengths for primes under 2000. And this talks about computing the period length for primes of "moderate" size.

I don't believe there is a surefire way of calculating it for large primes, there is some interesting information regarding period lengths in this paper, starting on page 31.

The maximum number of digits in a period integer is one less than the prime number itself. Thus the maximum period length for the prime number 7 is 6, and that for the prime number 271 is 270. Actual period lengths may be less than maximum, but necessarily are sub-multiples of it.

dfish
  • 140
  • I think the runtime of calculating the period just slows down horribly the bigger you go, no matter what. It's better than brute-forcing it by doing manual division. – Victor Resnov Apr 16 '22 at 03:14