JavaScript (ES6) 170 175 196 98 100
Edit New version, handles bigger numbers using digits array. Score almost doubled :-(
Multiplying digit by digit is more difficult, summing the digits is simpler.
F=(a,b,n)=>
(t=>{
for(r=t;--n;r[n]=s)
for(k=1,y=t,z=a;z;z=z/b|0)
t=[...t.map(v=>(v=c+(k?w*~~y[i++]+v:w*v),s+=d=v%b,c=v/b|0,d),
w=z%b,s=c=0,i=--k),c]
})([1])||r.sort((a,b)=>a-b)
Less golfed
F=(a, b, n) =>
{
var r=[1]; // power 0 in position 0
for(w=[]; w.push(a%b),a=a/b|0; ); // a in base b
for(t = [1]; --n; )
{
// calc next power, meanwhile compute digits sum
y=[...t]
k=1
w.map(w=>
(t=[...t.map(v=>(
v = c + (k?w*~~y[i++]+v:w*v),
d = v % b, // current digit
s += d, // digits sum
c = (v-d)/b, // carry
d)
,s=c=0,i=--k),c]
)
);
r[n] = s // store sum in result array (positions n-1..1)
}
return r.sort((a,b)=>a-b) // sort result in numeric order
}
My first attempt using doubles
, fails for big numbers.
JS doubles have 52 mantissa bits when for instance 15^14 needs 55 bits.
F=(a,b,n,r=[1])=>(x=>{for(;--n;r[n]=s)for(t=x*=a,s=0;t;t=(t-d)/b)s+=d=t%b})(1)
||r.sort((a,b)=>a-b)
Less golfed
F=(a, b, n) =>
{
var r=[1]; // power 0 in position 0
for(x = 1; --n; )
{
x *= a; // calc next power starting at 1
for(t = x, s = 0; t; t = (t-d) / b) // loop to find digits
{
d = t % b;
s += d;
}
r[n] = s // store sum in result array (positions n-1..1)
}
return r.sort((a,b)=>a-b) // sort result in numeric order
}
Test In Firefox/FireBug console
;[[2,5,10],[3,2,20],[5,6,1],[6,6,11],[6,8,20],[8,2,10],[15,17,18]]
.forEach(t=>console.log(...t,F(...t)))
2 5 10 [1, 2, 4, 4, 4, 4, 4, 4, 8, 8]
3 2 20 [1, 2, 2, 3, 4, 5, 6, 6, 6, 8, 9, 10, 11, 11, 13, 14, 14, 14, 15, 17]
5 6 1 [1]
6 6 11 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
6 8 20 [1, 6, 6, 8, 8, 8, 13, 13, 15, 20, 22, 22, 22, 27, 29, 34, 34, 34, 36, 41]
8 2 10 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
15 17 18 [1, 15, 17, 31, 31, 33, 49, 49, 63, 65, 81, 95, 95, 95, 95, 113, 127, 129]
Can I take a,b,n separated by newlines as input to my program? – FryAmTheEggman – 2015-03-09T15:32:49.423
@FryAmTheEggman Any reasonable input format is fine. – randomra – 2015-03-09T22:13:10.923