Problem 3

This one took a while due to having to find ways of doing things that
could cope with huge numbers.