#include <iostream>
using namespace std;
int main(void)
{
int n, m, sum, t;
while (cin >> n >> m)
{
sum = 0;
t = 0;
for (int i = n; i <= m; i++)
{
sum += i;
if (sum > m)
{
t++;
break;
}
if (sum <= m)
{
t++;
}
}
cout << t << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
int n, m, sum, t;
while (cin >> n >> m)
{
sum = 0;
t = 0;
for (int i = n;; i++, t++)
{
sum += i;
if (sum > m)
{
t++;
break;
}
}
cout << t << endl;
}
return 0;
}
反倒是簡潔的方法能過= =
for (int i = n; i <= m; i++)
i<=m刪掉,因為有可能i>m時,總和還沒超過m
感謝大佬! 成功AC了!!!!