All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Repeating decimals (Posted on 2006-09-25) Difficulty: 3 of 5
The decimal expansion of 1/271 repeats with a period of length 5:
.003690036900369 ...

However, it is not the smallest number q for which the decimal expansion of 1/q has a repetition length of 5.

Find the smallest q so that the decimal expansion of 1/q has repetition length n for each of {1, 2, ..., 10}

Is there a simple way of finding such a number?

See The Solution Submitted by Jer    
Rating: 4.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Hints/Tips computer exploration | Comment 1 of 12

When a fraction repeats with a length of n, it can be represented as a fraction with the denominator consisting of n 9's. That fraction is of course not necessarily in its reduced form. For example, 1/271 = .0036900369... = 369/99999, and the 1/271 is the fraction in its simplest (reduced) form.

Therefore q must be a factor of the repeated-9 number. The question is how to determine which factor will work.

The case of length 1 is ambiguous, as any terminating decimal can be said to have length 1, with its repeating 0's, as in q=1, 1/1 = 1.0000.... Otherwise the smallest q would be 3, giving .333....

Here's a table for the first 12 lengths:

length    prime factors of rep-9   smallest q   prime factors of smallest q
2            3 3 11                     11       11
3            3 3 3 37                   27       3 3 3
4            3 3 11 101                 101      101
5            3 3 41 271                 41       41
6            3 3 3 7 11 13 37           7        7
7            3 3 239 4649               239      239
8            3 3 11 73 101 137          73       73
9            3 3 3 3 37 333667          81       3 3 3 3
10           3 3 11 41 271 9091         451      11 41
11           3 3 21649 513239           21649    21649
12           3 3 3 7 11 13 37 101 9901  707      7 101

I can't see a pattern of the choice of prime factor(s) that make up the smallest q.

DEFDBL A-Z
DECLARE SUB factor (num, s$)
DIM SHARED nFct
DIM SHARED fct(30)
CLS
FOR i = 2 TO 12
 nbr = VAL(STRING$(i, "9"))
 factor nbr, f$
 f$ = LTRIM$(f$) + " "
 PRINT i, f$; TAB(41);
 nFct = 0
 DO
  ix = INSTR(f$, " ")
  IF ix > 0 THEN
   n = VAL(LEFT$(f$, ix - 1))
   f$ = MID$(f$, ix + 1)
   nFct = nFct + 1
   fct(nFct) = n
  END IF
 LOOP UNTIL f$ = ""
 lowestP = 999999999999999#
 FOR combo = 1 TO INT(2 ^ nFct - .5)
  prod = 1: pwr2 = 1
  FOR j = 1 TO nFct
   IF pwr2 AND combo THEN prod = prod * fct(j)
   pwr2 = pwr2 * 2
  NEXT
  q$ = LTRIM$(STR$(1 / prod))
  IF LEFT$(q$, 1) = "0" THEN q$ = MID$(q$, 2)
  q2$ = ""
  FOR j = 1 TO LEN(q$)
   ts$ = MID$(q$, j, 1)
   tst = INSTR("0123456789", ts$)
   IF tst > 0 THEN q2$ = q2$ + ts$
   IF ts$ = "E" OR ts$ = "D" THEN EXIT FOR
  NEXT
  FOR l = 1 TO i
   good = 1
   FOR j = l + 1 TO LEN(q2$) - 1
    IF MID$(q2$, j - l, 1) <> MID$(q2$, j, 1) THEN good = 0: EXIT FOR
   NEXT
   IF good THEN replen = l: EXIT FOR
  NEXT
  IF replen = i THEN
   IF prod < lowestP THEN lowestP = prod
  END IF
 NEXT
 PRINT lowestP;
 factor lowestP, fc$
 PRINT TAB(50); fc$

NEXT

SUB factor (num, s$)
 s$ = "": n = ABS(num): IF n > 0 THEN limit = SQR(n):  ELSE limit = 0
 IF limit <> INT(limit) THEN limit = INT(limit + 1)
 dv = 2: GOSUB DivideIt
 dv = 3: GOSUB DivideIt
 dv = 5: GOSUB DivideIt
 dv = 7
 DO UNTIL dv > limit
   GOSUB DivideIt: dv = dv + 4 '11
   GOSUB DivideIt: dv = dv + 2 '13
   GOSUB DivideIt: dv = dv + 4 '17
   GOSUB DivideIt: dv = dv + 2 '19
   GOSUB DivideIt: dv = dv + 4 '23
   GOSUB DivideIt: dv = dv + 6 '29
   GOSUB DivideIt: dv = dv + 2 '31
   GOSUB DivideIt: dv = dv + 6 '37
   IF INKEY$ = CHR$(27) THEN s$ = CHR$(27): EXIT SUB
 LOOP
 IF n > 1 THEN s$ = s$ + STR$(n)
 EXIT SUB

DivideIt:
 DO
  q = INT(n / dv)
  IF q * dv = n AND n > 0 THEN
    n = q
    s$ = s$ + STR$(dv)
    IF n > 0 THEN limit = SQR(n):  ELSE limit = 0
    IF limit <> INT(limit) THEN limit = INT(limit + 1)
   ELSE
    EXIT DO
  END IF
 LOOP
 RETURN
END SUB

 

 


  Posted by Charlie on 2006-09-25 11:03:49
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (21)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information