Assumption: When dividing an integer n
by another integer m
, and representing the result as a decimal in base b
, it will have recurring decimals iif m
has at least a prime factor that's not in n
, and it's not common with b
.
Examples:
6 / 100
when represented in base 10 it does not (0.03), because100 = 2*2*5*5
, in which all factors are common with the ones of base 10 (2 and 5).100 / 6
in base 10 does have recurring decimals (16.6666....), because6 = 2*3
, which has 3 that's not common with the ones of base 10300 / 6
in base 10 on the other hand doesn't have recurring decimals (50), because the3
factor gets cleared out as it's common with the numerator.
These also apply when representing the number in any other base.
However, I need to figure this out working with numbers that are big, and that are not integers, but rational numbers, which I have represented as decimals.
So to use this method, I'd have to first transform each number to the rational representation a / b
by using the continued fraction method (which is already a long algorithm), then factor each number (which will probably be too big to do efficiently), then compare the factors using the method above to get the binary answer.
So I would like to know if there's any way to tell whether the result will have recurring decimals without having to factorise the original ones. As possible not-so-big example inputs (all in base 10 to make thinking easier):
3.94625 / 3
does result in recurring decimals:1.3154166666...
3.5623086 / 3
: doesn't result in recurring decimals:1.1874362
p
+q
, and then factoring the both of them.Applying the same method to the other example becomes more apparent of this problem:
3.5623086 / 3 = 35623086 / (10^7 x 3)
, yet it doesn't have recurring decimals because3
is a factor of35623086 = 2 × 3 × 47 × 126323
.So you have to factorise both
– Victor Oliva Apr 21 '22 at 15:57p
andq
. My question is - is there any way around this?10^n
can always be ignored. Onlyq
needs to be factorised, and ignoring every prime present in the base (in this case 10), we only need to check whetherq
dividesp
, which can be done through Euclidean algorithm. Sop
doesn't need to be factorised, butq
does. – Victor Oliva Apr 21 '22 at 16:02