题解:P12892 [蓝桥杯 2025 国 Java B] 弹跳鞋
include <iostream>
include <cmath>
using namespace std;
typedef long long LL;
int main() { LL L; cin >> L;
if (L == 0) {
cout << 0 << endl;
return 0;
}
LL delta = 1 + 8 * L;
LL sqrt_delta = sqrt(delta);
// 找到最小的x使得x*(x+1)/2 >= L
LL x = (1 + sqrt_delta) / 2;
while (x * (x + 1) / 2 < L) {
x++;
}
// 检查条件
while (true) {
LL sum = x * (x + 1) / 2;
LL diff = sum - L;
if (diff >= 0 && diff % 2 == 0) {
cout << x << endl;
return 0;
}
x++;
}
return 0;
}