how to calculate the number of terms