公式序列

Formula Sequence

我需要帮助找到下一道题的数列公式。

我目前的想法和想法是Sn=n(10^n-1)/9,但在某些情况下它只是有效...

问题描述如下:

Description

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:

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...

For this problem, you have to write a program that calculates the i-th term in the sequence. That is, determine Sn(i).

Input specification

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 <= i <= 2 * 10^9). Input ends with a test case in which i is 0, and this case must not be processed.

Output specification

For each test case in the input, you must print the value of Sn(i) in a single line.

Sample input

1
25
100
0

Sample output

1
7
14

感谢单飞!我编写了代码,但在线法官显示我超过了时间限制,我的错误可能是什么?

#include <iostream> #include <math.h> using namespace std; int main() {int i;
int NTS;
cin>>i;
while (i>=1){
    NTS=ceil((sqrt(8*i+1)-1)/2);
    cout<<" "<<NTS<<endl;
    cin>>i;
}
return 0;}  

图案看起来像金字塔。
等级 : 1 3 6 10 15 21 28...
否:1 2 3 4 5 6 7...

Level = n(n+1)/2 => elements
3     = 3*4/2    => 6
6     = 6*7/2    => 21 

F(n) = 上限((sqrt(8*n+1)-1)/2)


假设 F(n) = a.

那么 n ~= a * (a+1) / 2.

重新排列:a^2 + a - 2n ~= 0.

求解:a = F(n) = (-1 + sqrt(1+8n)) / 2.
忽略否定答案。