互联2032ldw @ 2021-01-10 21:38:18
#include <stdio.h>
int del(int k)
{
int x=1;
int sum=0;
while(k!=0)
{
if(k>x)
sum+=x*x;
k=k-x;
x++;
if(k<=x)
{
sum+=k*x;
return sum;}
}
}
int main()
{
int k;
scanf("%d",&k);
printf("%d",del(k));
return 0;
}
by _Empty @ 2021-01-10 21:43:44
@互联2032ldw
#include<bits/stdc++.h>
using namespace std;
int main()
{
int l,i,bg=0;
cin>>l;
for(i=1;l-i>=0;l-=i++)
bg+=i*i;
cout<<bg+l*i;
return 0;
}
给您看看我的代码,太迟了,我没法帮您改
by 互联2032ldw @ 2021-01-10 22:07:24
Ok,但还是希望来个大佬改一下
by 犄角旮旯 @ 2021-01-18 23:00:28
@互联2032ldw 两个if的判断出了问题, k>x改为 k>=x; k<=x 改为 k<x
by _YyD_ @ 2021-06-08 15:11:53
考虑一下1的情况