AOJ.592 神奇的叶子

神奇的叶子

Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB
Total Submission: 920 Submission Accepted: 410

Description

自然界中的很多事物都遵循着数学的规律。在热带雨林中生长着一种植物,它的叶片呈漩涡状排列在根的周围,并且叶片的长度构成了一个等差数列。最里面的一片叶子最短,长度为a1。第二片、第三片、第k片叶子的长度分别为a1+d, a1+2*d, ai+(k-1)*d。
给定第一片叶子的长度a1,相邻叶子长度的差d、叶片个数n,请计算出所有叶片长度的和。

Input

一组数据,三个整数a1,n,d (1<=a1,n,d<=100)

Output

输出一个整数,表示所有叶片长度的和

Sample Input

1 2 3

Sample Output

5

题意分析

等差数列求和

代码总览

/*
    Title:AOJ.592
    Author:pengwill
    Date:2016-11-16
*/
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,n,d,sum;
    while(scanf("%d%d%d",&a,&n,&d)!= EOF){
        int final = a +(n-1) * d;
        sum= (a+final)* n/2;
        printf("%d\n",sum);
    }

    return 0;
}
posted @ 2016-11-16 16:11  pengwill  阅读(97)  评论(0编辑  收藏  举报