跳到正文

题解

题解:P12892 [蓝桥杯 2025 国 Java B] 弹跳鞋

#SUSPENDED#约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月19日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟
获赞
1
题目
P12892

版本

  1. v1当前

#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;

}

原文