Problem Description
有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。
 


 

Input
输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。
 


 

Output
对于每组输入数据,输出一个平均值序列,每组输出占一行。
 


 

Sample Input
3 2 4 2
 


 

Sample Output
3 6 3 7

#include<stdio.h>
int main()
{
    int n, m, sum, ave, sum1, ave1;
    int i, j, a, b;
    while( scanf( "%d%d", &n, &m ) == 2 )
    {
           if( n <= m )
           {
               sum = 2*n + n*(n-1);
               ave = sum / n;
               printf( "%d\n", ave );
           }
           else if( n > m )
           {
                a = n / m;
                b = n % m;
                if( b == 0 )
                {
                    for( i = 0 ; i < a; i++ )
                    {
                        sum = ( 2+ m*i*2 )*m + m*(m-1);
                        ave = sum / m;
                        printf( i == (a-1)?"%d\n":"%d ", ave );
                     }
                }
                else if( b != 0 )
                {
                    for( i = 0 ; i < a; i++ )
                    {
                        sum = ( 2+ m*i*2 )*m + m*(m-1);
                        ave = sum / m;
                        printf( "%d ", ave );
                     }
                    sum1 =  ( 2+ m*a*2 )*b + b*(b-1);
                    ave1 = sum1 / b ;
                    printf( "%d\n", ave1 );
                }
           }
    }

}

posted on 2011-11-16 00:43  狸の舞  阅读(162)  评论(0编辑  收藏  举报