[Question]
  [
Given an input `n`, write a program or function that outputs/returns the sum of the digital sums of `n` for all the bases 1 to `n`.
$$n + \sum\_{b=2}^n \sum\_{i=0}^\infty \left\lfloor \frac{n}{b^i} \right\rfloor \bmod b$$
### Example:
`n = 5`
---
Create the range `[1...n]`: `[1,2,3,4,5]`
---
For each element `x`, get an array of the base-`x` digits of `n`: `[[1,1,1,1,1],[1,0,1],[1,2],[1,1],[1,0]]`
bijective base-`1` of `5` is `[1,1,1,1,1]`
base-`2` (binary) of `5` is `[1,0,1]`
base-`3` of `5` is `[1,2]`
base-`4` of `5` is `[1,1]`
base-`5` of `5` is `[1,0]`
---
Sum the digits: `13`
---
### Test cases:
```
1    1
2    3
3    6
4    8
5    13
6    16
7    23
8    25
9    30
10   35
36   297
37   334
64   883
65   932
```
The sequence can be found on OEIS: [A131383](https://oeis.org/A131383)
### Scoring:
[code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"): The submission with the lowest score wins.
  
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 3 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
┬］∑
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXUyNTJDJXVGRjNEJXUyMjEx,i=NjU_,v=8)
Canvas beating Jelly?
```
{ ]   map over 1..input (implicit "{")
 ┬      decode input from that base
   ∑  sum the resulting (nested) array
```
[Answer]
# [Haskell](https://www.haskell.org/), 46 bytes
```
f n=sum$do a<-[1..n];mapM(pure[0..a])[1..n]!!n
```
[Try it online!](https://tio.run/##JY69DoMwDIR3nuJaMYCAiJ8WhhKWru3UEUVVJEKpCgGRIHh7GmDx2Z9PZzdc/UTbrmsNSdXU2VUPngdlRIhkt44PT2eYRlGGhHDmHvh0kmvHvxIUzuZ4Y5g0tFBaoShckH0mGAWvQPMcH6HvvdRCamUBcyNGsVsWk2D0pceHhA3V9LNhnoczgsIU0@3MqbG4lnVcoNi@iEK2rcsk9ZPMTy9@emVrHGd/ "Haskell – Try It Online")
## Explanation
The function `\b n -> mapM(pure[0..b])[1..n]`, generates all strings \$[0 \dotsc b]^n\$ in lexicographic order. For example:
```
mapM(pure[0..2])[0..1] == [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
```
By indexing into it with `(!!n)` this can be used to convert `n` to base `b+1`, however this won't work for unary (base-\$1\$), but we're summing the results.. We can even save some bytes with `a <- [1..n]` and using base-\$(n+1)\$ rather than a work-around for base-\$1\$ since we're missing \$[\underset{n\text{ times}}{\underbrace{1,\dotsc,1}}]\$ which is the same as \$[n]\$ when summing.
Using `do`-notation just concatenates all the lists instead of nesting them:
```
λ [ mapM (pure [0..a]) [1..5] !! n | a <- [1..5] ]
[[0,0,1,0,1],[0,0,0,1,2],[0,0,0,1,1],[0,0,0,1,0],[0,0,0,0,5]]
λ do a <- [1..5]; mapM (pure [0..a]) [1..5] !! n
[0,0,1,0,1,0,0,0,1,2,0,0,0,1,1,0,0,0,1,0,0,0,0,0,5]
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~39~~ 37
```
->n{(2..n).sum{|b|n.digits(b).sum}+n}
```
The only golfing here is removing some whitespace. [Try it online](https://tio.run/##KypNqvyfpmCrEPNf104jT7Naw0hPL09Tr7g0t7omqSZPLyUzPbOkWCMJLFSrnVf7v0AhTS85MSdHw8jIXPM/AA)
[Answer]
# [Python 2](https://docs.python.org/2/), 57 bytes
```
lambda n:sum(n/(k/n+2)**(k%n)%(k/n+2)for k in range(n*n))
```
This uses the formula $$a(n)=\sum\_{b=2}^{n+1}\sum\_{i=0}^{n-1}\left\lfloor\frac{n}{b^i}\right\rfloor\bmod b,$$ which works since \$\left\lfloor\frac{n}{(n+1)^0}\right\rfloor\bmod(n+1)=n\$.
[Try it online!](https://tio.run/##RYyxCsIwGAZnfYpvCf2TRkpSrVDQF1GHiMaW2L8lNoNPHy0IDjfcDTe9525kmz0OOOenG643B25faSCuKFRcWqkUBcFS/NSPEQE9Izp@3IkVS5mXyP9oNIyRKHGqG416r9Fsv@wu7Xo1xZ5nFMImbI4QdSogQKzhaTl9AA "Python 2 – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 14 [bytes](https://github.com/abrudz/SBCS)
```
+/∘∊⊢,⊢(⍴⊤⊣)¨⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X1v/UceMRx1dj7oW6QCxxqPeLY@6ljzqWqx5aMWj3s3/0x61TXjU22f0qKv5Ud/U4CBnIBni4RnMBaSBUmkKhnCWEZxlDGeZwFmmcJYZnGUOZ1nAWZYIkw0QBiL0GCM0mSFMN0MYb2SEUGFobGH8HwA "APL (Dyalog Unicode) – Try It Online")
### Explanation
Some parentheses are implied and can be added (lighter than the "official" parenthesizing):
```
+/∘∊(⊢,(⊢(⍴⊤⊣)¨⍳))
```
This is a monadic atop. Given an argument `Y`, this function behaves like:
```
+/∘∊(⊢,(⊢(⍴⊤⊣)¨⍳))Y
```
The two functions are applied in order. We'll start from the right one:
```
⊢,(⊢(⍴⊤⊣)¨⍳)
```
The are three functions in this train, so this is a fork. Given an argument `Y`, it acts as:
```
(⊢Y),((⊢Y)(⍴⊤⊣)¨⍳Y)
```
We can easily reduce to this (monadic `⊢` returns its argument, hence called *identity*):
```
Y,Y(⍴⊤⊣)¨⍳Y
```
Now, we know that `Y` is an integer (simple scalar, i.e. number or character), since we're given one. Therefore `⍳Y`, with `⎕IO=1`, returns `1 2 ... Y`. `⍳Y` actually returns an array with shape `Y` (`Y` must be a vector), where every scalar is the index of itself in the array (that's why monadic `⍳` is called the *index generator*). These indices are vectors, except for the case where `1≡⍴Y`, where they are scalars (this is our case).
Let's parse the middle function, `(⍴⊤⊣)¨`, next. `⍴⊤⊣` is the operand of `¨` (*each*), and the function is dyadic, so the `¨` operator will first reshape each length-1 argument to the shape of the other (that is, take the element and use it to replace every scalar in the other argument), and then apply the function to each pair of the two arguments. In this case, `⍳Y` is a vector and `Y` is a scalar, so, if `n≡⍴⍳Y`, then `Y` will be converted to `n⍴Y` (`⍴` represents the *shape* (monadic) and *reshape* (dyadic) functions). That is, in simpler terms, `Y` will be converted to an array containing `Y` times `Y`.
Now, for each pair, let's call the left argument `X` and the right `Z` (so that we don't conflict with the input `Y`). `⍴⊤⊣` is a dyadic fork, so it will expand to:
```
(X⍴Z)⊤X⊣Z
```
Let's make the easy first step of reducing `X⊣Z` to `X` (dyadic `⊣` is the *left* function):
```
(X⍴Z)⊤X
```
The `⍴` in `X⍴Z` is, again, the *reshape* function, so `X⍴Z`, in our case, is simply `X` times `Z`. `⊤` is the *encode* function. Given two arrays of numbers, where the left array is the base of each digit in the result (doesn't need to be integer or positive), i.e. the encoding, and the right is an array of numbers, returns the transposed array of those numbers in the specified encoding (transposition is the reversal of an array's dimensions relative to its elements). The representation of a digit is based on the quotient of the division of the number and the product of the less significant bases. If any base is `0`, it acts as base +∞. The arguments' scalars are all simple. Since `X` is a positive integer, and `X⍴Z` is a vector of equal elements, this is really just a case of converting `X` to base `Z` and reshaping to `X` digits. For \$X,Z\in\mathbb N\$, \$X\_Z\$ (\$X\$ in base \$Z\$) can't have more than \$X\$ digits, since \$X\_1\$ has \$X\$ digits. Therefore, `X⍴Z` is enough for our purposes.
The result of `Y(⍴⊤⊣)¨⍳Y` is, therefore, `Y` converted to each base from 1 to `Y`, possibly with leading zeroes. However, there is one issue: in APL, base 1 isn't special-cased, while this challenge does special-case it, so we have to include the sum of the base-1 digits of `Y` ourselves. Fortunately, this sum is just `Y`, since \$Y\_1=\underbrace{[1,1,...,1]}\_Y\$, so the sum is simply \$Y\times1=Y\$. It follows that we have to add `Y` somewhere into the array. This is how we do it:
```
Y,Y(⍴⊤⊣)¨⍳Y
```
I have already included this part here. Dyadic `,` is the *catenate* function, it concatenates its arguments on their last axes, and errors if that's not possible. Here, we simply concatenate the scalar `Y` to the vector `Y(⍴⊤⊣)¨⍳Y`, so that we increment the sum we're going to calculate by `Y`, as explained above.
The final part is the left function of our atop, `+/∘∊`:
```
+/∘∊Y,Y(⍴⊤⊣)¨⍳Y
```
`∘` is the *compose* operator. `f∘g Y` is the same as `f g Y`. However, we're using it here so that our train doesn't fork on the `∊`. So, we can reduce:
```
+/∊Y,Y(⍴⊤⊣)¨⍳Y
```
Now, it's time for the sum, but wait... there's a problem. The array isn't flat, so we can't just sum its elements before flattening it first. The *enlist* function `∊` flattens an array. Now that the array has been flattened, we finally use `+/` to sum it. `/` is the *reduce* operator, it applies a dyadic function between an array's elements on its second-to-last axis, with right-to-left priority. If the rank (number of dimensions, i.e. length of shape) of the array doesn't decrease, the array is then enclosed, although this is not the case here. The function that's applied here is `+`, which is the *plus* function that adds the pairs on the last axes of two arrays (and errors if the arrays can't be added like that). Here, it simply adds two numbers a number of times so that the reduce is completed.
Lo and behold, our train:
```
+/∘∊⊢,⊢(⍴⊤⊣)¨⍳
```
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 153 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][S N
S _Duplicate_input][N
S S N
_Create_Label_OUTER_LOOP][S N
S _Duplicate_top][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_PRINT][S S S N
_Push_0][S N
S _Duplicate_0][T   T   T   _Retrieve_input][N
S S T   N
_Create_Label_INNER_LOOP][S N
S _Duplicate][N
T   S S S N
_If_0_Jump_to_Label_AFTER_INNER_LOOP][S N
T   _Swap_top_two][S T  S S T   N
_Copy_1st_item_to_top][S T  S S T   T   N
_Copy_3rd_item_to_top][T    S T T   _Modulo][T  S S S _Add][S N
T   _Swap_top_two][S T  S S T   S N
_Copy_2nd_item_to_top][T    S T S _Integer_divide][N
S N
T   N
_Jump_to_Label_INNER_LOOP][N
S S S S N
_Create_Label_AFTER_INNER_LOOP][S N
N
_Discard_top][S T   S S T   S N
_Copy_2nd_item_to_top][T    S S S _Add][S N
T   _Swap_top_two][S S S T  N
_Push_1][T  S S T   _Subtract][N
S N
N
_Jump_to_Label_OUTER_LOOP][N
S S S N
_Create_Label_PRINT][S N
N
_Discard_top][T N
S T _Print_as_integer]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
[**Try it online**](https://tio.run/##PY1RCoAwDEO/k1P0DPvxPCID/RMUPH7XtHMbZF3ySL/zevtz70d3NzPGBaGTc4nJm8KfAihLH5QHSyhVrEqUlF@vMGZlTFxBYWtPRHMP1efe2jYA) (with raw spaces, tabs and new-lines only).
Port of [my Java 8 answer](https://codegolf.stackexchange.com/a/176982/52210), because Whitespace has no Base conversion builtins at all.
**Example run: [`input = 3`](https://tio.run/##PY1RCsAgDEO/k1P0DjvRGIL7Exzs@F3TOhViTR7p2@@nzXFezd3MGBeETs4lJm8JfwqgLH1QHiyhVLEqUVJ@vcKYlTFxB4XtPRGtPVSf@/EB)**
```
Command    Explanation                     Stack            Heap   STDIN  STDOUT  STDERR
SSSN       Push 0                          [0]
SNS        Duplicate 0                     [0,0]
TNTT       Read STDIN as integer           [0]              {0:3}  3
TTT        Retrieve input from heap 0      [3]              {0:3}
SNS        Duplicate 3                     [3,3]            {0:3}
NSSN       Create Label_OUTER_LOOP         [3,3]            {0:3}
 SNS       Duplicate 3                     [3,3,3]          {0:3}
 SSSTN     Push 1                          [3,3,3,1]        {0:3}
 TSST      Subtract (3-1)                  [3,3,2]          {0:3}
 NTSSN     If 0: Jump to Label_PRINT       [3,3]            {0:3}
 SSSN      Push 0                          [3,3,0]          {0:3}
 SNS       Duplicate 0                     [3,3,0,0]        {0:3}
 TTT       Retrieve input from heap 0      [3,3,0,3]        {0:3}
 NSSTN     Create Label_INNER_LOOP         [3,3,0,3]        {0:3}
  SNS      Duplicate 3                     [3,3,0,3,3]      {0:3}
  NTSSSN   If 0: Jump to Label_AFTER_IL    [3,3,0,3]        {0:3}
  SNT      Swap top two                    [3,3,3,0]        {0:3}
  STSSTN   Copy (0-indexed) 1st            [3,3,3,0,3]      {0:3}
  STSSTTN  Copy (0-indexed) 3rd            [3,3,3,0,3,3]    {0:3}
  TSTT     Modulo (3%3)                    [3,3,3,0,0]      {0:3}
  TSSS     Add (0+0)                       [3,3,3,0]        {0:3}
  SNT      Swap top two                    [3,3,0,3]        {0:3}
  STSSTSN  Copy (0-indexed) 2nd            [3,3,0,3,3]      {0:3}
  TSTS     Integer divide (3/3)            [3,3,0,1]        {0:3}
  NSNTN    Jump to LABEL_INNER_LOOP        [3,3,0,1]        {0:3}
  SNS      Duplicate 1                     [3,3,0,1,1]      {0:3}
  NTSSSN   If 0: Jump to Label_AFTER_IL    [3,3,0,1]        {0:3}
  SNT      Swap top two                    [3,3,1,0]        {0:3}
  STSSTN   Copy (0-indexed) 1st            [3,3,1,0,1]      {0:3}
  STSSTTN  Copy (0-indexed) 3rd            [3,3,1,0,1,3]    {0:3}
  TSTT     Modulo (1%3)                    [3,3,1,0,1]      {0:3}
  TSSS     Add (0+1)                       [3,3,1,1]        {0:3}
  SNT      Swap top two                    [3,3,1,1]        {0:3}
  STSSTSN  Copy (0-indexed) 2nd            [3,3,1,1,3]      {0:3}
  TSTS     Integer divide (1/3)            [3,3,1,0]        {0:3}
  NSNTN    Jump to LABEL_INNER_LOOP        [3,3,1,0]        {0:3}
  SNS      Duplicate 0                     [3,3,1,0,0]      {0:3}
  NTSSSN   If 0: Jump to Label_AFTER_IL    [3,3,1,0]        {0:3}
 NSSSSN    Create Label_AFTER_IL           [3,3,1,0]        {0:3}
  SNN      Discard top                     [3,3,1]          {0:3}
  STSSTSN  Copy (0-indexed) 2nd            [3,3,1,3]        {0:3}
  TSSS     Add (1+3)                       [3,3,4]          {0:3}
  SNT      Swap top two                    [3,4,3]          {0:3}
  SSSTN    Push 1                          [3,4,3,1]        {0:3}
  TSST     Subtract (3-1)                  [3,4,2]          {0:3}
  NSNN     Jump to LABEL_OUTER_LOOP        [3,4,2]          {0:3}
 SNS       Duplicate 2                     [3,4,2,2]        {0:3}
 SSSTN     Push 1                          [3,4,2,2,1]      {0:3}
 TSST      Subtract (2-1)                  [3,4,2,1]        {0:3}
 NTSSN     If 0: Jump to Label_PRINT       [3,4,2]          {0:3}
 SSSN      Push 0                          [3,4,2,0]        {0:3}
 SNS       Duplicate 0                     [3,4,2,0,0]      {0:3}
 TTT       Retrieve input from heap 0      [3,4,2,0,3]      {0:3}
 NSSTN     Create Label_INNER_LOOP         [3,4,2,0,3]      {0:3}
  SNS      Duplicate 3                     [3,4,2,0,3,3]    {0:3}
  NTSSSN   If 0: Jump to Label_AFTER_IL    [3,4,2,0,3]      {0:3}
  SNT      Swap top two                    [3,4,2,3,0]      {0:3}
  STSSTN   Copy (0-indexed) 1st            [3,4,2,3,0,3]    {0:3}
  STSSTTN  Copy (0-indexed) 3rd            [3,4,2,3,0,3,2]  {0:3}
  TSTT     Modulo (3%2)                    [3,4,2,3,0,1]    {0:3}
  TSSS     Add (0+1)                       [3,4,2,3,1]      {0:3}
  SNT      Swap top two                    [3,4,2,1,3]      {0:3}
  STSSTSN  Copy (0-indexed) 2nd            [3,4,2,1,3,2]    {0:3}
  TSTS     Integer divide (3/2)            [3,4,2,1,1]      {0:3}
  NSNTN    Jump to LABEL_INNER_LOOP        [3,4,2,1,1]      {0:3}
  SNS      Duplicate 1                     [3,4,2,1,1,1]    {0:3}
  NTSSSN   If 0: Jump to Label_AFTER_IL    [3,4,2,1,1]      {0:3}
  SNT      Swap top two                    [3,4,2,1,1]      {0:3}
  STSSTN   Copy (0-indexed) 1st            [3,4,2,1,1,1]    {0:3}
  STSSTTN  Copy (0-indexed) 3rd            [3,4,2,1,1,1,2]  {0:3}
  TSTT     Modulo (1%2)                    [3,4,2,1,1,1]    {0:3}
  TSSS     Add (1+1)                       [3,4,2,1,2]      {0:3}
  SNT      Swap top two                    [3,4,2,2,1]      {0:3}
  STSSTSN  Copy (0-indexed) 2nd            [3,4,2,2,1,2]    {0:3}
  TSTS     Integer divide (1/2)            [3,4,2,2,0]      {0:3}
  NSNTN    Jump to LABEL_INNER_LOOP        [3,4,2,2,0]      {0:3}
  SNS      Duplicate 0                     [3,4,2,2,0,0]    {0:3}
  NTSSSN   If 0: Jump to Label_AFTER_IL    [3,4,2,2,0]      {0:3}
 NSSSSN    Create Label_AFTER_IL           [3,4,2,2,0]      {0:3}
  SNN      Discard top                     [3,4,2,2]        {0:3}
  STSSTSN  Copy (0-indexed) 2nd            [3,4,2,2,4]      {0:3}
  TSSS     Add (2+4)                       [3,4,2,6]        {0:3}
  SNT      Swap top two                    [3,4,6,2]        {0:3}
  SSSTN    Push 1                          [3,4,6,2,1]      {0:3}
  TSST     Subtract (2-1)                  [3,4,6,1]        {0:3}
  NSNN     Jump to LABEL_OUTER_LOOP        [3,4,6,1]        {0:3}
 SNS       Duplicate 1                     [3,4,6,1,1]      {0:3}
 SSSTN     Push 1                          [3,4,6,1,1,1]    {0:3}
 TSST      Subtract (1-1)                  [3,4,6,1,0]      {0:3}
 NTSSN     If 0: Jump to Label_PRINT       [3,4,6,1]        {0:3}
NSSSSN     Create Label_PRINT              [3,4,6,1]        {0:3}
 SNN       Discard top                     [3,4,6]          {0:3}
 TNST      Print top (6) to STDOUT as int  [3,4]            {0:3}         6
                                                                                  error
```
Program stops with an error: No exit found. (Although I could add three trailing newlines `NNN` to get rid of that error.)
[Answer]
# Java 8, ~~76~~ 65 bytes
```
n->{int r=n,b=n,N;for(;b>1;b--)for(N=n;N>0;N/=b)r+=N%b;return r;}
```
-11 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##fZG9boMwFIX3PMUVUiUsFxpCQqq6Zu9QLxnbDjYhkVNyiYyJVEU8O7VpBEvF4J9z/Pnca/kkrzI67b/7opJNA@9S420BoNGW5iCLEoSXgwFF@ObsY2kACXNut3BTY6XVBQhA4NBjlN88ajg@KjcEO9QmZCpPmIoi4oXgyES@ZOKJK2IoFw@KmdK2BsGwrmc@9NKqyoXes6@13sPZdRburNF4/PgCSf7a8oG@nuYJA/3Kk6VbKCXDIcDup7HlOa5bG1/cTVthqGnw8mkDinERajK8418uSLORS7NZcDuB2zkwW49gtp4FNxO4mQNXq6m228@hSfqcjqwX5P6HXf8L)
**Explanation:**
```
n->{           // Method with integer as both parameter and return-type
  int r=n,     //  Result-sum, starting at the input to account for Base-1
      b=n,     //  Base, starting at the input
      N;       //  Temp integer
  for(;b>1     //  Loop the Base `b` in the range [n, 1):
      ;b--)    //    After every iteration: Go to the next Base (downwards)
    for(N=n;   //   Set `N` to the input `n`
        N>0;   //   Loop as long as `N` isn't 0 yet:
        N/=b)  //     After every iteration: Divide `N` by the Base `b`
      r+=N%b;  //    Increase the result `r` by `N` modulo the Base `b`
  return r;}   //  Return the result-sum `r`
```
[Answer]
**SAS, ~~81~~ 74 bytes**
```
data;input n;s=n;do b=2to n;do i=0to n;s+mod(int(n/b**i),b);end;end;cards;
```
Input is entered after the `cards;` statement, on newlines, like so:
```
data;input n;s=n;do b=2to n;do i=0to n;s+mod(int(n/b**i),b);end;end;cards;
1
2
3
4
5
6
7
8
9
10
36
37
64
65
```
Outputs a dataset containing the answer `s` (along with helper variables), with a row for each input value
[![enter image description here](https://i.stack.imgur.com/ouycx.png)](https://i.stack.imgur.com/ouycx.png)
Ungolfed:
```
data; /* Implicit dataset creation */
input n; /* Read a line of input */
s=n; /* Sum = n to start with (the sum of base 1 digits of n is equal to n) */
do b=2to n; /* For base = 2 to n */
    do i=0to n; /* For each place in the output base (output base must always have less than or equal to n digits) */
        /* Decimal value of current place in the output base = b^i      */
        /* Remainder = int(b / decimal_value)                           */
        /* Current place digit = mod(remainder, base)                   */
        s+mod(int(n/b**i),b);
    end;
end;
cards;
1
2
3
```
[Answer]
# Japt `-x`, 6 bytes
```
ÆìXÄ x
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=xuxYxCB4&input=OAoteA==)
```
õ!ìU c
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=9SHsVSBj&input=OAoteA==)
[Answer]
# [J](http://jsoftware.com/), ~~24~~ 23 bytes
```
+1#.1#.]#.inv"0~2+i.@<:
```
[Try it online!](https://tio.run/##RY7LCsIwEEX3/YpLuyhSDXm0eWFBEFy5cu9KLNaF7lz66zFkcAKZwDncYe4ztaJfMEf02EIi5tkJHC/nUxpUJ/K7dmJ9fVr51cMqDvuYNs399nhDYcaSf4DYFNbMtrBh9oVHZkULUxW0YVloSrgqpiJ8vSmLCFVQQkleCY56WI6YkYzjZp4O2fFvgtFkcrsm/QA "J – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 6 bytes
I really wish that there was something like `M` for `cmap` :(
```
Σ§ṁ`Bḣ
```
[Try it online](https://tio.run/##yygtzv7//9ziQ8sf7mxMcHq4Y/H///9NAQ "Husk – Try It Online") or [test all!](https://tio.run/##AUoAtf9odXNr/21TbytgKyIgLT4gIsivc@KCgXLCtv/Oo8Kn4bmBYELhuKP///8xCjIKMwo0CjUKNgo3CjgKOQoxMAozNgozNwo2NAo2NQ "Husk – Try It Online")
### Explanation
```
Σ§ṁ`Bḣ  -- example input: 5
 §      -- fork the argument..
     ḣ  -- | range: [1,2,3,4,5]
   `B   -- | convert argument to base: (`asBase` 5)
  ṁ     -- | and concatMap: cmap (`asBase` 5) [1,2,3,4,5]
        -- : [1,1,1,1,1,1,0,1,1,2,1,1,1,0]
Σ       -- sum: 13
```
## Alternatively, 6 bytes
```
ΣΣṠMBḣ
```
[Try it online](https://tio.run/##ARYA6f9odXNr///Oo86j4bmgTULhuKP///81 "Husk – Try It Online") or [test all!](https://tio.run/##AUoAtf9odXNr/21TbytgKyIgLT4gIsivc@KCgXLCtv/Oo86j4bmgTULhuKP///8xCjIKMwo0CjUKNgo3CjgKOQoxMAozNgozNwo2NAo2NQ "Husk – Try It Online")
### Explanation
```
ΣΣṠMBḣ  -- example input: 5
  Ṡ     -- apply .. 
     ḣ  -- | range: [1,2,3,4,5]
           .. to function applied to itself
   MB   -- | map over left argument of base
        -- : [[1,1,1,1,1],[1,0,1],[1,2],[1,1],[1,0]]
 Σ      -- flatten: [1,1,1,1,1,1,0,1,1,2,1,1,1,0]
Σ       -- sum: 13
```
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 5 bytes
```
LвOO+
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f58Imf3/t//@NzQA "05AB1E (legacy) – Try It Online")
Explanation:
```
LвOO+  //Full program
L      //push [1 .. input]
 в     //for each element b, push digits of input converted to base b
  O    //sum each element
   O   //sum each sum
    +  //add input
```
In 05AB1E (legacy), base 1 of 5 is [0,0,0,0,0], not [1,1,1,1,1]. Therefore after summing the range, add the input to account for the missing base 1.
I am using 05AB1E (legacy) because in current 05AB1E, base 1 of 5 is [1]. In order to account for this, I would either need to decrement the result by 1 or remove the first element of the range, both of which would cost 1 byte.
[Answer]
# Desmos, 127 bytes
$$f\left(n\right)=\sum\_{b=2}^{n+1}\sum\_{i=0}^{n-1}\operatorname{mod}\left(\operatorname{floor}\left(\frac{n}{b^i}\right),b\right)$$
```
f\left(n\right)=\sum_{b=2}^{n+1}\sum_{i=0}^{n-1}\operatorname{mod}\left(\operatorname{floor}\left(\frac{n}{b^i}\right),b\right)
```
[Try it here!](https://www.desmos.com/calculator/nwyhin9y2j) Defines a function \$f\$, called as \$f\left(n\right)\$. Uses the formula given in [Dennis's answer](https://codegolf.stackexchange.com/a/176951/31957).
Here is the resulting graph (point at \$(65, 932)\$):
[![graph generated on desmos.com](https://i.stack.imgur.com/vmxaL.png?s=256)](https://i.stack.imgur.com/vmxaL.png?s=256)
## Desmos, 56 bytes
This might not work on all browsers, but it works on mine. Just copy and paste the formula. This is \$f\_2(n)\$ in the above link.
```
f(n)=\sum_{b=2}^{n+1}\sum_{i=0}^{n-1}mod(floor(n/b^i),b)
```
[Answer]
# [Perl 6](http://perl6.org/), ~~45~~ 41 bytes
```
{$^a+sum map {|polymod $a: $_ xx*},2..$a}
```
*-4 bytes thanks to Jo King*
[Try it online!](https://tio.run/##DclLCoAgFAXQrVxCGlRIX4M@LqV4UI4SpQgSc@3W9By7n4eI2iFVmKNnC@XXraHJwr/WHE6bDYwGsBXPk4Wi5pxRiBc5JL/NEl79GRIoc2KafMV5VQY0Ak0P0UJ0Uo7xAw "Perl 6 – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 60 bytes
```
function(n){if(n-1)for(i in 2:n)F=F+sum(n%/%i^(0:n)%%i)
n+F}
```
[Try it online!](https://tio.run/##Pci9CoAwDATgvU/RpZAgYqqdRNc@RhchkMEI/kzis9fg4HD3HbdX9lNb@dLllE1B8RYGbSPytoN4Ud@PinnOzXGtoKELUoDsCkHQaZOfCpFo7Imw/MvFlIrFHMzBMVjjR8L6Ag "R – Try It Online")
Fails for `n>143` since `144^144` is larger than a `double` can get. Thanks to [Josh Eller](https://codegolf.stackexchange.com/users/84282/josh-eller) for suggesting replacing `log(n,i)` with simply `n`.
The below will work for `n>143`; not sure at what point it will stop working.
# [R](https://www.r-project.org/), 67 bytes
```
function(n){if(n-1)for(i in 2:n)F=F+sum(n%/%i^(0:log(n,i))%%i)
n+F}
```
[Try it online!](https://tio.run/##BcE7CoAwEAXA3lOkCewSRWMZtM0xBBFWFvQl@ClEPHucOYqYoSlyY7k0gcCvCqHxLOkgNQrTB3AcozvvnWBbqxN1YUsroVZma5UruPiVc855e8gH39XC5Qc "R – Try It Online")
Uses the classic `n%/%i^(0:log(n,i))%%i` method to extract the base-`i` digits for `n` for each base `b>1`, then sums them and accumulates the sum in `F`, which is initialized to `0`, then adding `n` (the base `1` representation of `n`) to `F` and returning the result. For `n=1`, it skips the bases and simply adds `n` to `F`.
[Answer]
# [Python 2](https://docs.python.org/2/), 61 bytes
```
f=lambda n,b=2.:n and n%b+f(n//b,b)+(n//b>1/n==0and f(n,b+1))
```
[Try it online!](https://tio.run/##HcxBCsIwFIThtZ5iNqENeTYm1QqF9CLiIqFGC/paQl14@pi6GBj44Vu@63Nmm3N0L/8OowdTcLbpGZ5HsAgq1qx1oCDV/wxGs3PHrZZCQRkpc5wTGBMjeX7ca0MwRkLh2naE9kLoTmXnW7/fLWniFZWwHxwGiMbGCgJF2rhC/QA "Python 2 – Try It Online")
Though this is longer the [Dennis's solution](https://codegolf.stackexchange.com/a/176951/20260) off which it's based, I find the method too amusing to not share.
The goal is to recurse both on lopping off the last digit `n->n/b` and incrementing the base `b->b+1`, but we want to prevent the base from being increased after one or more digits have been lopped off. This is achieved by make the base `b` a float, so that after the update `n->n//b`, the float `b` infects `n` with its floatness. In this way, whether `n` is a float or not is a bit-flag for whether we've removed any digits from `n`.
We require that the condition `1/n==0` is met to recurse into incrementing `b`, which integers `n` satisfy because floor division is done, but floats fails. (`n=1` also fails but we don't want to recurse on it anyway.) Otherwise, floats work just like integers in the function because we're careful to do floor division `n//b`, and the output is a whole-number float.
[Answer]
# JavaScript (without recursion), 77 bytes
Returns correct value for "any" number. [Try it online](https://tio.run/##HY1BDsIgEEX3PcW4MBlCq@3CFU7vApVqTTsYQF1Az47Et/lv8ZP31B8dJr@8YsfuZkuZCbk1bRA0pu9jWS1ioJAzRjLEQoyDSFGSOQZlCDdCcw65FyJnVvXYHbbd2/j2DFHtRdPQ/1HN7DwyEGgFDNe68lJNSgGpAZgcB7fa0@rutQ8z1pRq9vID)
```
f=(n,b,s)=>{while((s=s||(t=b=n))>1){t+=b%s;b=(m=(b/s|0))||n;s=s-!m}return t;}
```
# JavaScript (with recursion), 54 bytes
Returns correct value for maximum number 3867 ("Maximum call stack size exceeded" is thrown for larger input). [Try it online](https://tio.run/##DYxBCsIwEADvfcV6ELIk0agIYlx9S1IbsbQb6YoX49tjTjMwMGP4BOmX5@ttOd@HWhMpNtEI0lUJSSkqEiPa3S2uRacW1UxxK8VhKWzErmY8xxrocDo636W8KAaC4IHh0qj3rqnWCN8OoM8seRo2U360E7Qdou9@9Q8)
```
f=(n,b,s)=>(s=s||(b=n))-1?b%s+f(n,(m=b/s|0)||n,s-!m):b
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
bRFS
```
[Try it online!](https://tio.run/##y0rNyan8/z8pyC34v6GBQpCCtYKxmY6xuY6ZiY6ZqcKhrQpH9ygcbn/UtEbB/T8A "Jelly – Try It Online")
### How it works
```
bRFS  Main link. Argument: n
 R    Range; yield [1, ..., n].
b     Convert n to back k, for each k to the right.
  F   Flatten the resulting 2D array of digits.
   S  Take the sum.
```
[Answer]
# JavaScript (ES6), 42 bytes
This version is almost identical to my main answer but relies on arithmetic underflow to stop the recursion. The highest supported value depends on the size of the call stack.
```
f=(n,b=1,x)=>b>n?n:~~x%b+f(n,b+!x,x?x/b:n)
```
[Try it online!](https://tio.run/##FcvRCoJAEEbhe5/i7yJw2K0w6EYbfRbX3ChkRjRiIPLVt@3ucOB79u9@HZbH/DqI3saUIpfiA1feiNvQSif1ttk@uPj/bmfeOjuFWihFXUoBo2oguDLOlxzOET4FMKisOo3HSe8ZImuipvimHw "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), ~~51 48~~ 44 bytes
```
f=(n,b=2,x=n)=>b>n?n:x%b+f(n,b+!x,x?x/b|0:n)
```
[Try it online!](https://tio.run/##ZY9BDoIwFET3ngIXJjSgQAuUkhTOQhGIhvwaMaYL715j/F343b6Xmcxch@ewjffL7XEEe568n3UMqdE8dRqY7kwHPbTuYJL5w5O9S13vMvPKW2B@tLDZdTqtdonnuIgYi7IsKna/nCMXhAvkNeEl8obwKvTTojoI2iRRcJpogqiIUGFrTkSRo6AJUWOVktRIjIiSDi7xYfN3pfoaJbh/Aw "JavaScript (Node.js) – Try It Online")
### Commented
```
f = (             // f = recursive function taking:
  n,              // - n = input
  b = 2,          // - b = current base, initialized to 2
  x = n           // - x = current value being converted in base b
) =>              //
  b > n ?         // if b is greater than n:
    n             //   stop recursion and return n, which is the sum of the digits of n
                  //   once converted to unary
  :               // else:
    x % b +       //   add x modulo b to the final result
    f(            //   and add the result of a recursive call:
      n,          //     pass n unchanged
      b + !x,     //     increment b if x = 0
      x ?         //     if x is not equal to 0:
        x / b | 0 //       update x to floor(x / b)
      :           //     else:
        n         //       reset x to n
    )             //   end of recursive call
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 22 bytes
```
{1⊥⍵,∊(1+⍳⍵-1)⊥⍣¯1¨⊂⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v9rwUdfSR71bdR51dGkYaj/q3Qzk6BpqgkUXH1pveGjFo64moFjt/7RHbRMe9fY96pvq6f@oq/nQeuNHbROBvOAgZyAZ4uEZ/P9R76q0Qys0gKYYGmjqGJspGJsrmJkomJkCAA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 30 bytes
```
n->n+sum(b=2,n,sumdigits(n,b))
```
[Try it online!](https://tio.run/##DYrBCoAgEAV/Zem00grlXf8lCWUPvUTt@20vwzBMu7r62lahuOAT9vE9nGMQiNmtVedgSHZulbczKNIpFA6h1hXTwkY@GQrD2fQD "Pari/GP – Try It Online")
[Answer]
# C (gcc), ~~67~~ 56 bytes
```
b,a,s;e(n){for(b=a=n;a>1;a--)for(s=n;s;s/=a)b+=s%a;n=b;}
```
Port of [my Java 8 answer](https://codegolf.stackexchange.com/a/176982/52210).  
-11 bytes thanks to *@OlivierGrégoire*'s golf on my Java answer.
[Try it online.](https://tio.run/##NY3NDoIwEITvfYrGhKQNJVpQNK7rk3DZ8mN6sBLKjfDstVU4zbczk522eLVtCEaR8tALJ5fhMwmDhA7oqYGKQibHx9uDPyJJk6PPCBwaWMObrBNyYZynlnUzt6iB2wfqU5Q8lzHifBRWAkta1TtcN6jPO1w2KMs909WtirgyNv6f/6bGKfIgDll3b@asa9xBWdXHiVQNXw)
**Explanation:**
```
b,             // Result integer
a,             // Base integer
s;             // Temp integer
e(n){          // Method with integer as parameter
  for(b=a=n;   //  Set the result `b` to input `n` to account for Base-1
               //  And set Base `a` to input `n` as well
      a>1      //  Loop the Base `a` in the range [input, 1):
      ;a--)    //    After every iteration: Go to the next Base (downwards)
    for(s=n;   //   Set `s` to input `n`
        s;     //   Inner loop as long as `s` is not 0 yet:
        s/=a)  //     After every iteration: Divide `s` by Base `a`
      b+=s%a;  //    Add `s` modulo Base `a` to the result `b`
  n=b;}        //  Set input `n` to result `b` to 'return it'
```
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), 71 bytes
```
(load library
(d S(q((N)(sum(map sum(map* to-base(1to N)(repeat-val N N
```
[Try it online!](https://tio.run/##LctBDsIgEIXhfU8xy1eTJmIV9RJseoJpyoKECgKa9PRIBjffLN78xb0O73KsFT7wRt6tidMxYKMFb8CMyJ8dO0f63xOVMK2cLVQJ1PZko@UyfdmTIVOxkBqH5kWcxat4E7V4Fx/iU1TnHvR97g@6l7ql9Qc "tinylisp – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
+ssjLQS
```
[Test suite](http://pythtemp.herokuapp.com/?code=%2BssjLQS&test_suite=1&test_suite_input=1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A36%0A37%0A64%0A65&debug=0)
##### Explanation:
```
+ssjLQS   | Full program
+ssjLQSQQ | with implicit variables filled
----------+--------------------------------------------------
    L SQ  | Map over each d in [1..input]:
   j Q    |  input to base d as a list (unary is a list of 0)
 ss       | Sum of sums
+       Q | Add input (to account for unary)
```
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 25 bytes
```
{Sum!`'^^ToBase[_,2:_]'_}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@786uDRXMUE9Li4k3ymxODU6XsfIKj5WPb72v19qakpxtEpBQXJ6LFdAUWZeSUhqcYkzUFFxdJqOgqGVoYG6sZm6sbm6mYm6mWnsfwA "Attache – Try It Online")
## Explanation
```
{Sum!`'^^ToBase[_,2:_]'_}
{                       }   anonymous lambda, input: _
                            example: 5
         ToBase[_,   ]      convert `_`
                  2:_       ...to each base from 2 to `_`
                            example: [[1, 0, 1], [1, 2], [1, 1], [1, 0]]
                      '_    append `_`
                            example: [[1, 0, 1], [1, 2], [1, 1], [1, 0], 5]
       ^^                   fold...
     `'                     the append operator over the list
                            example: [1, 0, 1, 1, 2, 1, 1, 1, 0, 5]
 Sum!                       take the sum
                            example: 13
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
ＩΣＥＩθΣ↨Ｉθ⁺²ι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8M3sQDCKdTUUQAJOCUWpyJEAnJKizWMdBQyNcHA@v9/0/@6ZTkA "Charcoal – Try It Online") Link is to verbose version of code. Charcoal can't convert to base 1, but fortunately the digit sum is the same as the conversion to base \$n + 1\$. Explanation:
```
    θ           First input
   Ｉ            Cast to integer
  Ｅ             Map over implicit range
        θ       First input
       Ｉ        Cast to integer
      ↨         Converted to base
           ι    Current index
         ⁺      Plus
          ²     Literal 2
     Σ          Sum
 Σ              Grand total
Ｉ               Cast to string
                Implicitly print
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 49 bytes
```
.+
$*
1
11$`;$_¶
+`\b(1+);(\1)+
$1;$#2$*1,
1+;
1
```
[Try it online!](https://tio.run/##DcmxDYMwFEXR/q6Rj2QwivIwmEQegCWQ4iBRpKFAzMYALObktGdfj@/2KZWbcrl7rEFIlpO9rxOf58XJ18nNqv@rZLfOGrXIJ1ApoiPQMxAZefJCD0IkjMSeOPwA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
.+
$*
```
Convert to unary.
```
1
11$`;$_¶
```
List all the numbers from 2 to \$n + 1\$ (since that's easier than base 1 conversion).
```
+`\b(1+);(\1)+
$1;$#2$*1,
```
Use repeated divmod to convert the original number to each base.
```
1+;
```
Delete the list of bases, leaving just the base conversion digits.
```
1
```
Take the sum and convert to decimal.
[Answer]
# Desmos, 51 bytes
Inspired by [Conor O'Brien's answer](https://codegolf.stackexchange.com/a/176976/16293) and looking at the OEIS-entry I came up with my own Desmos-solution:
```
h(n)=n^2-\sum_{p=2}^n(p-1)\sum_{k=1}^n floor(n/p^k)
```
[Try it online!](https://www.desmos.com/calculator/zyakvkc5d7)
[Answer]
# APL(NARS), 29 chars, 58 bytes
```
{+/+/¨⍵{(⍺⍴⍨⌊1+⍺⍟⍵)⊤⍵}⍨¨1+⍳⍵}
```
little test on how to use:
```
  h←{+/+/¨⍵{(⍺⍴⍨⌊1+⍺⍟⍵)⊤⍵}⍨¨1+⍳⍵}
  h¨1 2 4 10 36 37 64 65
1 3 8 35 297 334 883 932 
                   
```
]