Is there an algorithm that can calculate the digits of a repeating-decimal ratio without starting at the beginning?
I\'m looking for a solution that doesn\'t use ar
Ad hoc I have no good idea. Maybe continued fractions can help. I am going to think a bit about it ...
UPDATE
From Fermat's little theorem and because 39 is prime the following holds. (=
indicates congruence)
10^39 = 10 (39)
Because 10 is coprime to 39.
10^(39 - 1) = 1 (39)
10^38 - 1 = 0 (39)
[to be continued tomorow]
I was to tiered to recognize that 39 is not prime ... ^^ I am going to update and the answer in the next days and present the whole idea. Thanks for noting that 39 is not prime.
The short answer for a/b
with a < b
and an assumed period length p
...
k = (10^p - 1) / b
and verify that it is an integer, else a/b
has not a period of p
c = k * a
c
to its decimal represenation and left pad it with zeros to a total length of p
Example
a = 3
b = 7
p = 6
k = (10^6 - 1) / 7
= 142,857
c = 142,857 * 3
= 428,571
Padding is not required and we conclude.
3 ______
- = 0.428571
7