首页 > 代码库 > hdu 2015 偶数求和

hdu 2015 偶数求和

水题啦 直接贴代码

 

#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<queue>#include<stack>#define mem(a,b) memset(a,b,sizeof(a))#define ll __int64#define MAXN 1000#define INF 0x7ffffff#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int a[500];int main(){    int m,n,i,j;    while(scanf("%d%d",&n,&m)!=EOF)    {        for(i=1;i<=n;i++)        {            a[i]=i*2;        }        int sum=0;        if(m!=1)        {for(i=1;i<=n;i++)        {            sum+=a[i];            if(i%m==0)            {                printf("%d",sum/m);                if(i!=n) printf(" ");                sum=0;            }        }        if(n%m!=0)                printf("%d",sum/(n%m));                printf("\n");        }        else        {            for(i=1;i<=n;i++)            {                printf("%d",i*2);                printf("%c",i==n?‘\n‘:‘ ‘);            }        }    }    return 0;}