Recall that a geometric progression is a sequence (a_n) defined as follows
a_1 = a
a_n = a * r^(n - 1) for all integers n > 1
where a and r are some fixed numbers and r /= 0 is called the common ratio of a sequence.
Let's denote S_n as the sum of the first n terms of this sequence.
Case r = 1
Then all the terms are equal to a so
S_n = na
Case r /= 1
Then we have
S_n = a_1 + a_2 + … + a_n = a + ar + … a*r^(n - 1) = a * (1 + r + … + r^(n – 1))
Now the formula for the difference between two n-th powers tells us that
r^n - 1 = r^n – 1^n = (r - 1) * (1 + r + … + r^(n-1))
and since r /= 1 we can divide both sides by r – 1 to have
1 + r + … + r ^(n - 1) = (r^n - 1) / (r – 1)
Finally, substituting this expression into the first equality we get
S_n = a * (r^n - 1) / (r – 1)