Java, 18 17 bytes
n->(n=n*n-~n)*n/8
Port of @tsh' JavaScript answer, so make sure to upvote him/her as well.
-1 byte thanks to @tsh.
Try it online.
(n=n*n-~n)
could alternatively be (n+=n*n+1)
for the same byte-count:
Try it online.
Explanation:
n-> // Method with integer as both parameter and return-type
(n= // Replace `n` with:
n*n // `n` squared
-~n) // `+n+1`
*n // Square that new `n`
/8 // Integer-divide that by 8 to get the result
A literal implementation would be 56 bytes in comparison:
n->{int t=0;for(;n>0;)t+=n--;for(;t>0;)n+=t--;return n;}
Try it online.
Explanation:
n->{ // Method with integer as both parameter and return-type
int t=0; // Temp-integer, starting at 0
for(;n>0;) // Loop `n` down until it's 0:
t+=n // Add the current `n` to the temp-integer `t`
--; // And then decrease `n` by 1
// (at this point, `n=0`)
for(;t>0;) // Now loop `t` down until it's 0:
n+=t // Add the current `t` to `n`
--; // And then decrease `t` by 1
return n;} // Return the modified `n` as result