洛谷也有哈
#include<iostream>
using namespace std;
int n,s,k;
int main(){
cin>>n;
while(n>0) s+=n,n-=++k;
cout<<s;
}
哈哈哈哈哈哈,代码是什么意思呢?
以6天为例:1 2 2 3 3 3
n=6,s+=6, 0 1 1 2 2 2, k=1, n=5;
n=5,s+=5, 0 0 0 1 1 1, k=2, n=3;
n=3,s+=3, 0 0 0 0 0 0, k=3, n=0;
退出while循环。
总结如下:对每个数取1,和为n,k记录当前1的数量。n会随k的变化而变化。