1042 求等差数列的和
Submit solution
Points:
100
Time limit:
1.0s
Memory limit:
32M
Problem types
Allowed languages
C, C++, Java, Python
Description
有一些整数组,每三个整数为一组,分别表示等差数列的起始位置、终止位置和公差,求每组数列的和。如果三个整数都为0,表示输入结束。
Sample
Input
5 100 5
1 5 1
1 10 1
0 0 0
Output
1050
15
55
Comments
include<iostream>
using namespace std; int main(){ long long a,b,d; while(cin>>a>>b>>d){ if(a==0&&b==0&&d==0)break; long long n=(b-a)/d+1; long long sum=n*(a+b)/2; cout<<sum<<endl; } return 0; }