题解 | #[NOIP2015]金币#
[NOIP2015]金币
http://www.nowcoder.com/practice/8f71f5670e6a45118d24d13868a2da9e
#include <stdio.h>
int main(){
int k,sum=0,i=1;
scanf("%d",&k);
while(k>i){
sum+=i*i;
k-=i;
i++;
}
sum+=i*k;
printf("%d",sum);
return 0;
}
int main(){
int k,sum=0,i=1;
scanf("%d",&k);
while(k>i){
sum+=i*i;
k-=i;
i++;
}
sum+=i*k;
printf("%d",sum);
return 0;
}