
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Write out a few cases. It can be seen that all items greater than <code>primeOne * primeTwo</code> can always be bought.
If we can buy items with cost <code>i</code>, we can also buy items with price <code>i + primeOne</code> and <code>i + primeTwo</code>.
Use dynamic programming.
There is an O(1) solution: Use the Chicken McNugget Theorem.