For example, lets say we have the number 100, and want to find the minimum number of times 2,3 and 4 fit in it. For this all of the given numbers must be used.
Ex. 4 can fit in 23 times, 3 twice, and 2 once, giving 28 as the minimum amount of times these numbers fit. What I did in my head is guess and check. I tried to come up with an algorithm by taking the sum of the other smaller numbers, subtracting from the total, and finding how many times the largest number fits into that one. Subtract the result of how many times that number fits by the number. From there the steps are repeated. Example:
100 & 2,3,4
2+3 = 5
100 - 5 = 95
4 fits in 95 23 times giving 92
4 * 23 = 92
100-92 =8
8-2 = 6
3 fits into 6 twice
8 - 6 = 2
2 fits into 2 once
end.
This does not work for all values though. Could you point me to the right direction? Thanks.
Let $N \geq 9$ be your number. We always need to take at least one $2, 3$, and $4$, so let's just take one of each to start with. This leaves us with the number $N - 9$, and there are only two cases to consider.
If the number $N - 9$ is divisible by $4$, just take all $4$'s because being greedy clearly beats any other solution.
If the number $N - 9$ is not divisible by $4$, then reduce it to a number that is divisible by $4$ (by taking $2$'s and $3$'s) with the fewest number of moves. There are a few sub-cases to consider here. Then we can take all $4$'s afterwards.
For your $N = 100$ case, we would first take one $2, 3,$ and $4$, which leaves us with $91$. Now $91$ isn't divisible by $4$, so we need to reduce it to a number that is divisible by $4$. The quickest way to do this is by taking $3$, which leaves us with $88$. Finally, we can take the remaining $22$ numbers to be $4$, which gives us $3 + 1 + 22 = 26$ as our final answer.