I have a pattern. I have a box made of $n\times n\times n$ boxes where n is a power of 2.
I flatten this box into an $n^3$ flat sequence of boxes.
I then have an $n/2 \times n / 2 \times n/2$ box, that I flatten and put right beside it.
So now my total number of boxes is $n^3 + (n/2)^3$.
We repeat this pattern for some number of iterations k which gives us the geometric series:
$\sum^k_{i=0} n (1/2^i)^3 = \sum^k_{i=0} n (1/2^3)^i$
Which we can calculate directly by doing:
$n\frac{1 - 8^{-k}}{1 - 8^{-1}}$
I have the problem that I need this calculation to be exact to the integer, but I am running into some numerical imprecision for large $n$ due to floating point limitations.
Is there a way to compute this series directly using integers alone? (Doing the actual sum is prohibitively expensive).