Speed up the 3n+1 solution by using cache