/*
水题 但是这个PE让我真的很气 最后一项不能有空格
*/
#include <stdio.h>// 我写的略复杂 #include <string.h>//hdu 2015 Presentation Error int main() { int a[105],n,c,m,b,i,j,s,f,sum; while(scanf("%d%d",&n,&m)!=EOF && (n!=0)) { b = n;f=0; for(int o=1;o<=n;o++)a[o]=2*o; sum = 0; while(b>=m) { if(m==1)sum=sum+2*m; else sum=m+1+2*m*f; b-=m; //sum=sum/m; if(f>0)printf(" "); printf("%d",sum);//可能多一个空格 f++; } if(b>0) { s=0; for(int k=n-b+1;k<=n;k++)s+=a[k]; s=s/b; printf(" %d ",s); } else printf(" ");//用个退格 不行 ? ,enmmm 不行 } return 0; }
#include <stdio.h>
int main(void)
{
int n, m;
while(scanf("%d%d", &n, &m) != EOF)
{
int sum=0, ai=2, count=0, i;
for(i=1; i<=n; i++)
{
sum += ai;
ai += 2;
if( i % m == 0) //每m次 输出一次
{
count++;
if(count != 1)
printf(" ");
printf("%d", sum / m);
sum = 0;
}
}
if(n % m == 0)
printf("
");
else
printf(" %d
", sum / (n % m)); //若有余数 则剩下取平均数
}
return 0;
}