CSU 1191: Staginner Is Smarter Than Gauss!
阿新 • • 發佈:2019-01-23
題目:
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<b). So he thought that he was smarter than Gauss.
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<a<b<10^4) which separate by one space.
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<iostream>
using namespace std;
int main()
{
int a, b;
while (cin >> a >> b)cout << (a + b)*(b - a + 1) / 2 << endl;
return 0;
}