似乎我这个“蒟蒻”跟各位DALAO想的不太一样
首先,输入n,使用一层循环搞定
具体思路:
使用ans作为累加器,k记录发几枚金币,s负责不断赋值给累加器,sum当这些天数的金币发完后,及时更新k, 每次发完,k--,证明发* 枚金币 少了一天,例如,k = 3时:
执行流程:
1.s = 3
2.ans += 3(ans = 3);
3.k--(k = 2);
1.s = 3
2.ans += 3(ans = 6);
3.k--(k = 1);
1.s = 3
2.ans += 3(ans = 9);
3.k--(k = 0);
4.k = sum(sum = 4;k = 4)
5.s = k(s = 4)
6.sum++(sum = 5)
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
int main() {
int n;int ans = 0,k = 1,s = k,sum = 2;
scanf("%d",&n);
for(int i = 1;i<=n;++i) {
ans+=s;
k--;
if(k == 0) {
k = sum;s = k;
sum++;
}
}
cout<<ans;
return 0;//不写return 0;成绩return 0;
}