CHAI_ @ 2020-03-24 22:14:12
#include <stdio.h>
int main()
{
int a[100001]={0};
int n=0,i=1,sum=0,k,num;
scanf("%d",&num);
for(;i<num;i=k)
{
n++;
for(k=i;k<i+n;k++)
{
a[k]=n;
}
}
for(int j=0;j<=num;j++)
{
sum+=a[j];
}
printf("%d",sum);
return 0;
}
by CHAI_ @ 2020-03-26 16:17:08
没有大佬来帮助我。。。。。
by pqliuyqq @ 2020-03-28 22:03:23
要是一次内层循环结束时i=num,就没有a[num],sum+=a[num]时就没有加进去
by pqliuyqq @ 2020-03-28 22:05:10
亲测没有其他bug
by CHAI_ @ 2020-03-30 21:50:41
@pqliuyqq
我还是不太明白.....
by pqliuyqq @ 2020-04-03 11:15:58
只用把第7行的i<num改成i<=num就行了...
by CHAI_ @ 2020-04-03 12:22:07
@pqliuyqq
过了!谢大佬
by pqliuyqq @ 2020-04-03 12:31:43
我也很蒻......