title: Weird way of calculating square root
body: <p>I've been told this code snippet is equivalent to <code>(int)sqrt(n)</code></p>
  
  <pre><code>int s(int n) {
      for (int i = 1, k = 0; n &gt; 0; i += 2) {
          if (k + i &gt; n)
              return i / 2;
          k += i;
      }
      return 0;
  }
  </code></pre>
  
  <p>And it seem to work,
  yet I don't understand how it works ?</p>