DECLARE SUB factor (num#, s$)
DECLARE FUNCTION frugal# (x#)
DEFDBL A-Z
CLS
ct = 0
FOR i = 1 TO 22000000
IF frugal(i) THEN
IF ct = 0 THEN
ct = 1
firstno = i
ELSE
ct = ct + 1
END IF
ELSE
IF ct > max THEN
max = ct
maxfirstno = firstno
PRINT maxfirstno, max
END IF
ct = 0
END IF
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$ + LTRIM$(STR$(n))
EXIT SUB
DivideIt:
count = 0
DO
q = INT(n / dv)
IF q * dv = n AND n > 0 THEN
n = q: count = count + 1: 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
IF count > 0 THEN
s$ = s$ + LTRIM$(STR$(dv))
IF count > 1 THEN s$ = s$ + LTRIM$(STR$(count))
END IF
RETURN
END SUB
FUNCTION frugal (x)
factor x, s$
IF LEN(s$) < LEN(LTRIM$(STR$(x))) THEN frugal = 1: ELSE frugal = 0
END FUNCTION
Finds that a sequence of two consecutive frugal numbers begins at 4374, and three consecutive frugal numbers begin at 1097873:
1097873 = 7*47^3*71
1097874 = 2*3^7*251
1097875 = 5^3*8783
|
Posted by Charlie
on 2012-09-14 15:59:58 |