Project Euler 13 with caching