Is there a formula for a sequence like $k^{t}-k^{t-1}+k^{t-2}-...+k^{2}-k^{1}+k^{0}$

58 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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