Determine all possible values of a positive integer N such that the product of the nonzero digits in the base-N representation of 2009 (base ten) is equal to 18 (base ten).
DEFDBL A-Z
CLS
num = 2009
goal = 18
REDIM dgt(10)
FOR n = 3 TO num
v = num
prod = 1
dCt = 0
ERASE dgt
REDIM dgt(10)
DO
dig = v MOD n
v = v \ n
IF dig > 0 THEN
prod = prod * dig
END IF
dgt(dCt) = dig
dCt = dCt + 1
LOOP UNTIL prod > goal OR v = 0
IF v = 0 AND prod = goal THEN
PRINT n; ": ";
FOR i = dCt - 1 TO 0 STEP -1
PRINT dgt(i);
NEXT
PRINT
END IF
NEXT
finds five bases where this works:
base representation
4 : 1 3 3 1 2 1
10 : 2 0 0 9
223 : 9 2
1000 : 2 9
1991 : 1 18
Note that 18 is used in this last as a base-1991 digit, rather than using the alphabetic representation of digits beyond 9.
|
Posted by Charlie
on 2010-06-13 14:43:10 |