zifeiyv @ 2024-11-04 23:13:11
include <stdio.h>
int main()
{
int k,s;
scanf("%d",&k);
int d = 0;
int i = 0;
while(k>d)//算出k是几组数的和
{
i++;
d += i;
}
for(int j = 1;j<=i;j++)//计算整组的金币数量(假设全部都是整组)
{
s += j * j;
}
if((d-k)!=0)
{
s = s-i*(d-k); //减去多余的金币数量
}
printf("%d",s);
return 0;
}
by yuanminQAQ @ 2024-11-05 18:18:09
同上,我和你思路几乎一模一样
by imx2g @ 2024-11-24 17:29:52
include上没#编译都过不了
by imx2g @ 2024-11-24 17:33:34
除此之外,s没初始化,初始化为0后可以ac