欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

P2669(金币)

程序员文章站 2024-01-12 09:29:52
...
#include <bits/stdc++.h>

using namespace std;

int main() {
    int k, total = 0, i = 1;
    scanf("%d", &k);
    while (k) {
        for (int j = 1; j <= i; j++)
            if (k > 0)
                total += i, k--;
            else {
                printf("%d\n", total);
                return 0;
            }
        i++;
    }
    printf("%d\n", total);
    return 0;
}