Find all integers n such that S(n) = S(2n) = ... = S(n*n), where S is the sum of the base-10 digits.
DECLARE FUNCTION sod! (x!)
FOR n = 1 TO 9999999
s = sod(n)
good = 1
FOR coef = 2 TO n
IF sod(coef * n) <> s THEN good = 0: EXIT FOR
NEXT coef
IF good THEN PRINT n
NEXT n
FUNCTION sod (x)
n$ = LTRIM$(STR$(x))
t = 0
FOR i = 1 TO LEN(n$)
t = t + VAL(MID$(n$, i, 1))
NEXT
sod = t
END FUNCTION
finds only
1
9
99
999
Nothing else up to 10 billion.
|
Posted by Charlie
on 2012-11-22 12:08:45 |