Counting the Pages of a Book

How many pages of a book are there between p. 10 and p. 40, inclusive? This is a problem where it is easy to make an off-by-one error, as the answer is not $$40-10=30.$$ We show how to solve it, along with generalizations to arithmetic and geometric sequences.