Optimum pack size purchases: part 3

Suppose I need quantity Q grams of honey, and I can buy packs of honey in either 340g or 454g pack sizes. These packs cost 1.79 and 2.19 respectively (cost per kilo is therefore 5.26 and 4.82 respectively)

I buy m packs of 340g and n packs of 454g

Question: express m & n in terms of Q in order to minimise cost for any given Q.

I believe this is a solution: https://www.experts-exchange.com/questions/29063883/Optimum-pack-size-purchases-follow-up-to-minimum-cost-solution.html

But this maybe overbaking it (the least common multiple of 340 and 454 is 77180)

Wandering if I'm missing a shortcut somewhere.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fred MarshallPrincipalCommented:
Well, I'd like to make sure the logic is clear, so:

1) Note that 454<2*340 so one would purchase as many of the larger packs as possible and then only one additional pack is needed of one size or the other.

2) Plan to purchase as many of the lower-cost packs as possible:
That quantity is n'=ROUNDDOWN(Q/454)

3) Plan to purchase the remaining quantity P=Q-n'*454.  If P<=340 buy one of the smaller packs.  ELSE buy one of the larger packs.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xeniumAuthor Commented:
Thanks Fred, that's exactly right. I believe in this case that summarises the solution completely.

I will post a follow-up working towards more complicated examples.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Math / Science

From novice to tech pro — start learning today.