Finding the nth term and calculating values