Show that if n is a power of 3, then $\sum_{i=0}^{\log_3n} 3^i = \frac{3n-1}{2}$
$\sum_{i=0}^{\log_3n} 3^i =3^0+3^1+3^2+3^3...+3^{log_3n}$
This is a geometric sequence, so I used the geometric sum formula: $S= \frac{a_1 \cdot (q^n-1)}{q-1}$.
The first element is : $ 3^0 = 1$,
The ratio is : $q=3$,
The number of elemnts (my n) is: $log_3n$. if n is a power of 3 , we get : $\log_3n= 3^x, x\in \mathbb N$. $\sum_{i=0}^{\log_3n} 3^i = \frac{3^0\cdot (3^{\log_3 n}-1)}{3-1}= \frac{3^{\log_3n}-1}{2}=\frac {3^\bbox[yellow]{3^x}-1}{2}$.
I can see that my $n$ needs to be $log_3n +1$, but I can't find a way to do so. I thought that because I am using a geometric sum formula and I'm summing from $0 $ to $log_3n$, instead of summing from : $1$, I have to sum $log_3n +1$, but it doesn't sound like a valid argument. Any help is greatly appreciated.
Make a change: $n=3^m$. Then: $$S=\sum_{i=0}^{m} 3^i=\frac{1\cdot (3^{m+1}-1)}{3-1}=\frac{3\cdot 3^m-1}{2}=\frac{3n-1}{2}.$$