Calculating the nth term