4. General case


In general case, the decimal part is consisted of repeating part and not repeating part. For example, 1/6 = 0.1[6].
We can find a repeating point when the same quotient and remainder occur during the iteration of division.

The program is as follows

 10   ' cycle_m
 20   '
 30   input N
 40   dim Q%(N),R%(N)
 50   for I=1 to N:Q%(I)=0:R%(I)=0:next I
 60   '
 70   A=1
 80   B=A*10\N:A=res
 90   Q%(A)=B:R%(A)=A
100   '
110   B=A*10\N:A=res
120   if and{Q%(A)=B,R%(A)=A} then 160
130   Q%(A)=B:R%(A)=A
140   goto 110
150   '
160   S=Q%(A):T=R%(A)
170   A=1:F=0
180   B=A*10\N:A=res
190   if and{B=S,A=T} then print "[";:F=1
200   Q%(A)=B:R%(A)=A:print B;
210   if F=0 then 180
220   '
230   B=A*10\N:A=res
240   if and{B=S,A=T} then print "]":end
250   Q%(A)=B:R%(A)=A:print B;:goto 230

The formula of the length of repeating decimal is,

let n be,

n = 2a * 5b * n',  (10, n') = 1
k = max {a, b}
e is the order of 10 at mod n'

then m/n is,

first k decimal digits does not repeat
repeating from (k+1) decimal digit, and its length is e.


previous index next

E-mail : kc2h-msm@asahi-net.or.jp
Hisanori Mishima