Solved problems 8 and 9

A number-theoretic solution to problem 9 exists, but I'll leave that until the
same task is needed in a later problem.