题目:
Description
Alice loves playing a PC game recently. In this game, you can cost 1 coin to upgrade a role from level 1 to level 2, 2 coins to upgraded a role from level 2 to level 3, 3 coins to upgrade a role from level 3 to level 4, etc.
If Alice has N coins and the level of her role is L, how many levels can her role be upgraded at most? Assume the level of a role has no upper bound.
Input
The first line contains the number of test cases T (1 ≤ T ≤ 200).
For each test case, there is only one line with two integers N, L (1 ≤ N, L ≤ 109) as defined above.
Output
For each test case, output how many levels can her role be upgraded at most.
Sample Input
5 6 7 7 7 14 7 15 7 10000 3
Sample Output
0 1 1 2 138
代码:
#include<iostream>
using namespace std;
int main()
{
int t, n, l;
cin >> t;
while (t--)
{
cin >> n >> l;
int ans = 0;
while (n >= l)n -= l, l++, ans++;
cout << ans << endl;
}
return 0;
}