Improved Problem 14 to use a cache.