Formula for sum of n terms of an AP