DECLARE FUNCTION sod# (x#)
DEFDBL AZ
CLS
FOR a = 1 TO 297
FOR b = a + 1 TO 298
FOR c = b + 1 TO 299
c1fl = 0: c2fl = 0
IF (a + b + c) MOD 3 = 0 THEN
c1ct = c1ct + 1
c1fl = 1
END IF
IF (sod(a) * sod(b) * sod(c)) MOD 5 = 0 THEN
c2ct = c2ct + 1
c2fl = 1
END IF
IF c1fl AND c2fl THEN bothct = bothct + 1
NEXT
NEXT
NEXT
PRINT c1ct; c2ct, bothct
FUNCTION sod (x)
s = 0
st$ = LTRIM$(STR$(x))
FOR i = 1 TO LEN(st$)
s = s + VAL(MID$(st$, i, 1))
NEXT
sod = s
END FUNCTION
finds
1470249 2135269 712009
meaning 712,009 meet both criteria and:
1,470,249 meet the first criterion and this constitutes the answer to B.
2,135,269 meet the second criterion and this is then the answer to part A.
Those that meet both criteria are also counted in the individual criterion counts.
These are out of the 4,410,549 possible combinations of numbers.

Posted by Charlie
on 20110730 17:42:18 