描述
题解
根据题目中的样例解释,我们完全可以大胆的猜测,次数至多不超过两次,所以一共可能是 0、1、2 次, 0 次很容易想就是
查看了官方题解,写的十分详细,贴给大家看看:
所以,这里除去考虑 0 次的情况,剩下只需要考虑
代码
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
ll n;
while (cin >> n)
{
if (n == 1)
{
cout << 0 << endl;
continue;
}
ll k = ((ll)sqrt(8 * n + 1) - 1) >> 1;
ll s = k * (k + 1) >> 1;
ll c = n * (n + 1) >> 1;
ll d = (ll)sqrt(c) * (ll)sqrt(c);
if (s == n || s + 1 == n || d == c || d + 1 == c)
{
cout << 1 << endl;
}
else
{
cout << 2 << endl;
}
}
return 0;
}