Calculating sequence terms