CSU 1191: Staginner Is Smarter Than Gauss!

题目:

Description

While Staginner was in primary school , he heard that Gauss could easily calculate the sum of 1+2+...+100 , however , Staginner could easily calculate the sum of integers between two positive integers a,b(a

So many people scorn at Staginner . So It's time for you to show to Staginner that it's a easy problem for you too.

Input

There are several lines in the input , each line has two integers a,b(0

Input file is end by EOF.

Output

There are several output lines carry with corresponding input lines , each line output a integer represent the result of a+(a+1)+...+(b-1)+b.

Sample Input

1 100
5 6

Sample Output

5050
11

代码:

#include
using namespace std;

int main()
{
	int a, b;
	while (cin >> a >> b)cout << (a + b)*(b - a + 1) / 2 << endl;
	return 0;
}

你可能感兴趣的:(CSU 1191: Staginner Is Smarter Than Gauss!)