Finding the number of terms in an AP