Store the calculated results in a vector or map or something. It's not harder than that.
Next time you're going to calculate the same thing, it's already saved somewhere, so fetch it and save the...