When will the decimals in a/b repeat?
(832) 422-8646
Contact
The previous post looked at how many digits are in the reduced fraction for the nth harmonic number. I was curious about how long the cycle of digits in a harmonic number might be.
I wrote about the period length for the digits of fractions almost a decade ago. This post includes code so I can apply it to harmonic demoninators.
from sympy import lcm, factorint, n_order
def period(n):<br>factors = factorint(n)<br>exp2 = factors.get(2, 0)<br>exp5 = factors.get(5, 0)<br>r = max(exp2, exp5)
d = n // (2**exp2 * 5**exp5)<br>s = 1 if d == 1 else n_order(10, d)<br>return (r, s)
This function returns two numbers: r is the number of non-repeating digits at the beginning and s is the length of the repeating part.
The following code
from functools import reduce
def lcm_range(n):<br>return reduce(lcm, range(1, n + 1))
print( period( lcm_range(50) ) )
prints (5, 1275120) meaning that 1/lcm(1, 2, 3, …, 49, 50) has five non-repeating digits following by 1,275,120 digits that repeat ad infinitum. And so the decimals in the expansion of H50 go have a cycle length of 1,275,120.
Leave a Reply<br>Your email address will not be published. Required fields are marked *<br>Comment *<br>Name *
Email *
Website
Search for:
John D. Cook, PhD
My colleagues and I have decades of consulting experience helping companies solve complex problems involving data privacy, applied math, and statistics.
Let’s talk. We look forward to exploring the opportunity to help your company too.