There is a serie that i want to calculate for a competitive programing question. $$\sum_{i=1}^n \left(81i \cdot 10^{i-1} - 10^{i-1} + 1\right) $$ Most of it is easy but at the end i end up with: $$\sum_{i=1}^n 10^{i-1} \cdot i $$
So it abstracts to: $$\sum_{i=1}^n P^i \cdot i : P\in ℤ_{>1}$$ I can implement an recursive function, but i get time limit for large numbers. How can i simplify this to a simple function, is it possible?
Hint:
From
$$1+2\cdot10+3\cdot 10^2+4\cdot 10^3+\cdots n\cdot 10^{n-1}$$ subtract $10$ times this number and simplify the equal powers of $10$. This leads you to the solution.