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
30 if N1 @ 2>0 and N1 @ 5>0 then
60 :while Num @ N1>0
70 :Num=10*Num+9:inc Lgth
90 :print N,N1,Lgth
95 :if Lgth=12 then end
which stops at N=707, which has period length 12, and is the first such.
Posted by Charlie
on 2012-11-30 12:22:52