Hi so I am working on a problem where I have to calculate $\sum\limits_{i=1}^n a^i$ modulo $10^9+7$.
I have to do this on a computer, so I have to avoid overflow. I was wondering if there will be a formula that can help me with my problem.
Hi so I am working on a problem where I have to calculate $\sum\limits_{i=1}^n a^i$ modulo $10^9+7$.
I have to do this on a computer, so I have to avoid overflow. I was wondering if there will be a formula that can help me with my problem.
in general, if $a\neq 1$ $$\sum_{k=0}^n a^k = \frac{a^{n+1} -1}{a-1}$$ For a proof, multiply by $a-1$ and observe the "telescopic" behavior of the lhs.
(Note that the sum starts with $k=0$, not $k=1$ as in your case).