Divide problem and store precomputed results to optimize execution time at the expense of used memory.