Finding the value of n and the sum of n terms