Calculating sum of consecutive powers of a number multiplied by a consecutive number

83 Views Asked by At

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?

2

There are 2 best solutions below

2
On BEST ANSWER

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.

0
On

You can use calculus; $$\begin{align} \sum_{i=1}^{n} P^i\cdot i &= P\sum_{i=1}^{n} P^{i-1}\cdot i\\ &= P\sum_{i=1}^{n} P^{i-1}\cdot i\\ &= P\frac{\mathbb d}{\mathbb dP}\left(\sum_{i=1}^{n} P^i\right)\\ &= P\frac{\mathbb d}{\mathbb dP}\left(P\cdot \frac{P^n-1}{P-1}\right) \end{align} $$ I think you can take it from here.