Digit sum of powers in bases You should write a program or function which outputs or returns the sum of the digits in base b representation of the first n natural power of a in ascending order.

Example for a = 2, b = 3  and n = 4

The base10 numbers are 2^0, 2^1, 2^2 and 2^3.
Their base3 representations are 1, 2, 11, 22.
The digit sums are 1, 2, 2, 4.
The sorted digit sums are 1, 2, 2, 4 which is the result.


Input


3 integers a &gt; 1, b &gt; 1  andn &gt; 0


Output


A list of integers


Examples

Input => Output

2 5 10 =&gt; 1 2 4 4 4 4 4 4 8 8
3 2 20 =&gt; 1 2 2 3 4 5 6 6 6 8 9 10 11 11 13 14 14 14 15 17
5 6 1 =&gt; 1
6 6 11 =&gt; 1 1 1 1 1 1 1 1 1 1 1
6 8 20 =&gt; 1 6 6 8 8 8 13 13 15 20 22 22 22 27 29 34 34 34 36 41
8 2 10 =&gt; 1 1 1 1 1 1 1 1 1 1
15 17 18 =&gt; 1 15 17 31 31 33 49 49 63 65 81 95 95 95 95 113 127 129


This is code-golf so shortest code wins.
CJam, 13 bytes
q~,f#\fb::+$p

I think this can be improved, but lets get this started.
The input is in the following order : b a n
Example input:
3 2 4

Output:
[1 2 2 4]

Code expansion:
q~             &quot;Read the input and parse it. Now we have on stack, b a and n&quot;
  ,            &quot;Get an array from 0 to n-1&quot;;
   f#          &quot;Get all the powers of a present in the array, i.e. 0 to n-1&quot;;
     \         &quot;Swap the array of a^i and bring the base on top&quot;;
      fb       &quot;For each number in the array, convert it into its base representation array&quot;;
        ::+    &quot;Calculate the sum of each of the sub arrays in the bigger array&quot;;
           $p  &quot;Sort and print the sum of digits of base representation of n powers of a&quot;;

Try it online here