title: Can this function be refactored to be O(1)
body: <p>I have this function which is used to calculate a value with diminishing returns. It counts how often an ever increasing value can be subtracted from the input value and returns the number of subtractions. It is currently implemented iteratively with an infinite loop:</p>
  
  <pre><code>// inputValue is our parameter. It is manipulated in the method body.
  // step counts how many subtractions have been performed so far. It is also our returned value.
  // loss is the value that is being subtracted from the inputValue at each step. It grows polynomially with each step.
  public int calculate(int inputValue) {
      for (int step = 1; true; step++) {// infinite java for-each loop
          int loss = (int) (1 + 0.0006 * step*step + 0.2 * step);
          if (inputValue &gt; loss) {
              inputValue -= loss;
          } else {
              return step;
          }
      }
  }
  </code></pre>
  
  <p>This function is used in various places within the larger application and sometimes in performance critical code. I would prefer it to be refactored in a way which does not require the loop anymore.</p>
  
  <p>I am fairly sure that it is possible to somehow calculate the result more directly. But my mathematical skills seem to be insufficient to do this.</p>
  
  <p>Can anybody show me a function which produces identical results without the need for a loop or recursion? It is OK if the refactored code may produce different results for extreme values and corner cases. Negative inputs need not be considered.</p>
  
  <p>Thank you all in advance.</p>