On New Years Day, Penny resolved to make poverty history.
Unfortunately Penny was penniless and asking her relatives for cash seemed a bit passe, so she asked them to contribute goats.
Frankie, Mark, Dolly, Squidly, Ruby and Draco each sent goat vouchers. Each of the vouchers was for a three figure number of goats. Penny was delighted with the response, over 5200 goats in total. Even better, she found that after using 11 of the goats to pay local administrative expenses, each of the beneficiaries would receive exactly 32 goats.
Curiously she noticed that the each of the donations was the product of exactly six prime numbers. If Frankie gave more than Mark, who gave more than Dolly, who gave more than Squidly, who gave more than Ruby, who gave more than Draco, how many did each give?
This program finds all three-digit numbers that have exactly six prime factors:
DEFDBL A-Z
CLS
FOR nbr = 100 TO 999
factor nbr, nfct$
fct = 0: st = 1
DO
ix = INSTR(st, nfct$, " ")
IF ix THEN fct = fct + 1
st = ix + 1
LOOP UNTIL ix = 0
IF fct = 6 THEN PRINT nbr; ",";
NEXT
END
SUB factor (num, s$)
s$ = "": n = ABS(num): IF n > 0 THEN limit = sqroot(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 = sqroot(n): ELSE limit = 0
IF limit <> INT(limit) THEN limit = INT(limit + 1)
ELSE
EXIT DO
END IF
LOOP
RETURN
END SUB
Those numbers are used as data in the following program:
DATA 144 , 160 , 216 , 224 , 240 , 324 , 336 , 352 , 360 , 400 , 416 , 486 , 504
DATA 528 , 540 , 544 , 560 , 600 , 608 , 624 , 729 , 736 , 756 , 784 , 792 , 810
DATA 816 , 840 , 880 , 900 , 912 , 928 , 936 , 992
DIM n(34)
FOR i = 1 TO 34: READ n(i): PRINT n(i): NEXT
FOR draco = 1 TO 29
t = n(draco)
FOR ruby = draco + 1 TO 30
t = t + n(ruby)
FOR squidly = ruby + 1 TO 31
t = t + n(squidly)
FOR dolly = squidly + 1 TO 32
t = t + n(dolly)
FOR mark = dolly + 1 TO 33
t = t + n(mark)
FOR frankie = mark + 1 TO 34
t = t + n(frankie)
IF t MOD 32 = 11 AND t >= 5200 THEN
PRINT n(draco); n(ruby); n(squidly); n(dolly); n(mark); n(frankie), t
END IF
t = t - n(frankie)
NEXT frankie
t = t - n(mark)
NEXT mark
t = t - n(dolly)
NEXT dolly
t = t - n(squidly)
NEXT squidly
t = t - n(ruby)
NEXT ruby
NEXT draco
It reports, in order from least (draco) to greatest (frankie), and the total:
729 810 880 912 936 992 5259
|
Posted by Charlie
on 2006-02-19 12:31:52 |