1 条题解

  • 1
    @ 2024-9-24 20:37:36
    #include <iostream>
    
    int main() {
        int n;
        std::cin >> n; // 输入要求的项数 n
    
        int k = 1; // 当前数字
        int count = 0; // 已经输出的数字个数
    
        // 循环查找
        while (true) {
            count += k; // 更新总数
            if (count >= n) { // 找到满足条件的 k
                std::cout << k << std::endl; // 输出当前数字 k
                break; // 退出循环
            }
            k++; // 移动到下一个数字
        }
    
        return 0;
    }
    
    
    • 1

    【入门】求数列的第n项的值是多少?

    信息

    ID
    436
    时间
    1000ms
    内存
    16MiB
    难度
    10
    标签
    递交数
    8
    已通过
    4
    上传者