Takes ~5.3s on my machine to get both outputs. Not sure how to optimize it any further other than running the math in threads? Took me longer than it should have to realize a lot of unnecessary math could be cut if the running total becomes greater than the target while doing the math. Also very happy to see that none of the inputs caused the recursive function to hit Python's max stack depth.
Thanks! yup, I figured there would be a way. You're right, much faster, on my machine with your code, this is the speed:
I'll have to take a look to understand how that works to be better.