Finding the nth term or sum