# 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.

Thanks
###### Who is Participating?

x
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.

PrincipalCommented:
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