In the known sequence {an}, when n is odd, an = 2N-1, when n is even, an = 3 ^ n, find the sum SN of the first n terms of the sequence

In the known sequence {an}, when n is odd, an = 2N-1, when n is even, an = 3 ^ n, find the sum SN of the first n terms of the sequence

S (n) = s (odd) + s (even)
When n is even, there are odd and even terms of N / 2 and N / 2
Then s (n) = n / 2 * a (1) + n / 2 * (n / 2-1) * D + [a (2) * (1-Q ^ n / 2)] / (1-Q)
Observing the situation, it is not difficult to see that d = 2, q = 1
The solution is s (n) = (substituting D, q)
When n is odd, there are (n + 1) / 2 odd term and (n-1) / 2 even term
Just replace the above formula n / 2 with (n + 1) / 2 and (n-1) / 2. If the input is too troublesome, I won't do it