Explanation:
that is
sum(2^r) for r=1 to n, plus sum(1/2) for r=1 to n.
and that is
sum(2^r) + n/2 for r=1 to n.
2^r is a geometric sequence with 2 being the common ratio (every new term is created by multiplying the previous term by 2).
and since r is starting at 1, the first term a1 = 2.
the formula for the sum of a finite geometric sequence is
Sn = a1×(1 - r^n) / (1 - r)
with r being the common ratio .
so, in our case
Sn = 2×(1 - 2^n) / (1 - 2)
Sn = (2 - 2^(n+1)) / -1 = 2^(n+1) - 2
and so, in total we get
2^(n+1) - 2 + n/2 = 2^(n+1) + (n - 4)/2