Sum of terms and finding the value of n