1
$\begingroup$

I am trying to solve a programming problem and my intended solution involves a calculation like this one:

$k^{t}-k^{t-1}+k^{t-2}-...+k^{2}-k^{1}+k^{0}$

The problem is that $t$ can be as large as $1,414,213,562$ so iterating isn't an option. Does anyone know of a formula for this?

$\endgroup$
  • 1
    $\begingroup$ en.wikipedia.org/wiki/Geometric_series $\endgroup$ – lab bhattacharjee Dec 20 '13 at 18:48
  • 1
    $\begingroup$ This looks like an alternating geometric sequence to me. $\endgroup$ – Module Dec 20 '13 at 18:49
  • $\begingroup$ Hint: The ratio between terms (r) is $-k$. The formula for geometric sum is $\frac{t_{1}\left( 1-r^{n} \right)}{1-r}$. $\endgroup$ – 1110101001 Dec 20 '13 at 19:03
6
$\begingroup$

You look for $$\sum_{p=0}^t (-k)^p=\frac{1-(-k)^{t+1}}{1+k}$$

$\endgroup$
  • $\begingroup$ Morning Sami. :+) $\endgroup$ – mrs Dec 21 '13 at 6:20
  • $\begingroup$ $\ddot \cup +1$ $\endgroup$ – Namaste Dec 21 '13 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.