题解 | #[NOIP2015]金币#
[NOIP2015]金币
https://www.nowcoder.com/practice/8f71f5670e6a45118d24d13868a2da9e
#include <stdio.h> int main() { int k = 0; while (1 == scanf("%d", &k)) { // 初始的金币数为1个 int gold = 1; // 总的金币数 int sum_gold = 0; int sum_day = 0; for (int day = 1; sum_day <= k; ) { if ((k - sum_day) >= day) { sum_gold += (day * gold++); sum_day += (day++); } else { sum_gold += (gold * (k - sum_day)); break; } } printf("%d\n", sum_gold); } return 0; }