When dividing two integers, there may be an infinite sequence of digits after the decimal point (e.g. in the cases of 1/3, 1/7 etc).
As far as I know, if the two numbers divided are integers, this infinite sequence will be, from some point, a repetition of a some finite sequence (this may be also true to dividing rational numbers and not just integers, but I'm keeping it simple for now).
Take for example 1/7, it is equal to 0.14285714285714285714285714285714...
The sequence repeating itself is 142857, a sequence of length 6.
Another example is 1/31, which is equal to 0.032258064516129032258064516129032...
The sequence repeating itself is 032258064516129, a sequence of length 15.
Some divisions do not immediately start with the repeating sequence, e.g. 3/14 which equals 0.21428571428571428571428571428571... (starting with 2, then followed by repetitions of 142857, a sequence of length 6).
Finally, after this long speech, here comes a question that bothers me for a long time: is it possible to find out the length of the repeating sequence using the 2 numbers being divided?
I'm looking for a function that receives a numerator and a denominator as parameters and returns the length of the repetitive sequence. Examples for input+output:
F(1,7) = 6
F(1,31) = 15
F(3,14) = 6
F(1,3) = 1
Does anyone know if this is possible? And if so - how to achieve it?