startingQuantity / numberAvailable = price
5 apples / 4 available = $1.25
So if there are 4 available and the price is 1.25 and someone buys three apples then they would pay 1.25 + 1.666 + 2.5 = $5.416
What is the equation to get 5.416?
I'm looking for an equation that will work for larger numbers. For example how would you figure it out if starting quantity was 1,000,000 and number available was 500,000 and someone wanted to buy 240,000?
Suppose there were $n$ apples available, with a starting quantity of $n+1$ and we wanted to buy $n$ apples. The total cost would be $s_n$ (I know this example isn't as general as you wanted, but I'm just trying to explain why what you're asking for is impossible).
$$s_n = \frac{n+1}{n}+\frac{n}{n-1}+...+\frac{2}{1}$$ $$t_n = \frac{1}{n}+\frac{1}{n-1}+...+\frac{1}{1}$$ $$s_n-t_n =\frac{n}{n}+\frac{n-1}{n-1}+...+\frac{1}{1}=n$$ so $$s_n=n+t_n$$ And the cost of buying $k$ apples would be $s_n-s_{n-k}$. Note that $t_n$ is the harmonic series, for which there is no general (simple) formula for, so I suspect that your search for a general formula won't be successful.