title: Finding the nearest quantity based on price and amount to get
body: <p>I've got a small maths problem in which I need to determine a quantity based on a cost price and a final amount.</p>
  
  <p>Now this is easy in theory as it's simply final amount/actual cost = quantity, except in my case the actual cost changes based on the quantity.</p>
  
  <p>Quantity = Final Amount / (Item Cost + Overhead Cost) where the overhead cost is on a sliding scale.</p>
  
  <p>An example would be
  If i want to make $500 for selling sheep, and the base price for each sheep is say $50, but the cost of selling one sheep is $5, so the actual cost would be $55 for one sheep, but if i sell 2 sheep then the cost of selling one becomes $7, so the actual cost would be $107 and so on and so forth.</p>
  
  <p>What would be the most optimal way to get to as close to the final amount (but not over) as possible, without having to loop almost unconditionally?</p>