title: Formula Sequence
body: <p>I need help finding the formula of the sequence for the next problem.</p>
  <p>What I think and have for now is <code>Sn=n(10^n-1)/9</code> but it just works in some cases...</p>
  <p>Here is the description of the problem:</p>
  <blockquote>
  <h3>Description</h3>
  <p>Sn is based upon the sequence positive integers numbers. The value n can be found n times, so the first 25 terms of this sequence are as follows:</p>
  <pre><code>1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7...
  </code></pre>
  <p>For this problem, you have to write a program that calculates the i-th term in the sequence. That is, determine <code>Sn(i)</code>.</p>
  <h3>Input specification</h3>
  <p>Input may contain several test cases (but no more than 10^5). Each test case is given in a line of its own, and contains an integer i (1 &lt;= i &lt;= 2 * 10^9). Input ends with a test case in which i is 0, and this case must not be processed.</p>
  <h3>Output specification</h3>
  <p>For each test case in the input, you must print the value of Sn(i) in a single line.</p>
  <h3>Sample input</h3>
  <pre><code>1
  25
  100
  0
  </code></pre>
  <h3>Sample output</h3>
  <pre><code>1
  7
  14
  </code></pre>
  </blockquote>
  <p>Thanks solopilot! I made the code but the online judge show me Time Limit Exceeded, what could be my error?</p>
  <pre><code>#include &lt;iostream&gt; #include &lt;math.h&gt; using namespace std; int main() {int i;
  int NTS;
  cin&gt;&gt;i;
  while (i&gt;=1){
      NTS=ceil((sqrt(8*i+1)-1)/2);
      cout&lt;&lt;&quot; &quot;&lt;&lt;NTS&lt;&lt;endl;
      cin&gt;&gt;i;
  }
  return 0;}  
  </code></pre>