Calculation of nth term and sum of terms in an AP