# How to calculate certain sum? [with detailed answer]

**anton_lunyov**#2

It is a simple exercise on sum of the geometric progression.

We have by the formula

**(a + b)^2 = a^2 + 2 * a * b + b^2**

that

Sum[(2^k + 1/2^k)^2 : 1<=k<=n] =

Sum[2^(2 * k) + 2 + 1/(2^(2 * k)) : 1<=k<=n] =

2 * n + Sum[4^k + (1/4)^k : 1<=k<=n] =

2 * n + (4^n-1) * 4/3 - ((1/4)^n-1) * 1/3 =

1/3 * (-3 - 4^(-n) + 4^(1 + n) + 6 * n)

Also refer to this

**junior94**#3

I don’t quite understand your question. Are you asking how to translate the above expression to code ? Please clarify

**anton_lunyov**#5

@lashabuxo

No way you can delete this now after I write the explanation

If it is your homework and you don’t want others to see that you ask for help then it will be a lesson to you.