题解 | 金币
金币
https://www.nowcoder.com/practice/8f71f5670e6a45118d24d13868a2da9e
#include <stdio.h>
int main()
{
int k = 0;
int days = 0;//记录已经累计的天数
int total = 0;//记录发放的总金币数量
int stage = 1;//记录发放金币的阶段
scanf("%d",&k);//输入总天数
while(1)
{
if(days + stage <= k)
{
total += stage * stage;
days += stage;
stage++;
}
else
{
int remain = k - days;
total += remain * stage;
break;
}
}
printf("%d",total);
return 0;
}
