Suppose a perfectly competitive firm has cost function $C(q) = 40 + 0.5q + 0.05q^2$. If the market price is $p = 8$, the profit made is maximized at $MR = MC \implies 8 = 0.5 + 0.1q \implies q^{*} = 75$. Further calculation tells us that profit is $> 0$.
Doesn't this violate the zero-profit condition in perfect competition? Maybe one can argue that it's the short-run cost function. What if it's actually the long-run cost function?
Edit: @Giskard mentions that the long-run price is supposed to be $0.5 + 2\sqrt{2}$ and it appears, after calculation, that $P = MC = AC$ indeed gives that. A further calculation tells us that $\max_q[\pi(q)] = \max[(0.5+8–√)q−c(q)]≈2.3⋅10−15>0$. Does that mean that a competitive market can not have a cost function $C(q)$ as mentioned?