Find the smallest base ten positive integer with period 12.
Note: The period of an integer is the length of the repeating pattern of reciprocal. For example, repeating pattern of the reciprocal of 7 is 1/7 = 0.142857142857..... having a length of 6. So the period of 7 is 6.
Powers of 2 and of 5 can be divided out of the integer while keeping the ultimate repeating interval the same. When the highest power of each that will divide the integer have been so divided out, the repetition begins immediately after the decimal point and so the denominator of a common fraction of the form k/(10^n  1) consists of all 9's, with the number of 9's being the length of the repeating cycle.
As the reduced integer (without powers of 2 or 5) will be smaller than any that incorporate powers of those primes, there's no need to examine any even number or multiple of 5.
The terminology Num (for numerator) in the below program comes from the derivation
n = k/999...99
k = 999...99/n
10 for N=1 to 99999
20 N1=N
30 if N1 @ 2>0 and N1 @ 5>0 then
50 :Num=9:Lgth=1
60 :while Num @ N1>0
70 :Num=10*Num+9:inc Lgth
80 :wend
90 :print N,N1,Lgth
95 :if Lgth=12 then end
100 next
which stops at N=707, which has period length 12, and is the first such.

Posted by Charlie
on 20121130 12:22:52 