1443: Simple and
Time limit: 2 Sec Memory Limit: 128 MBsubmit: 249 Resolution: 12
[ submit ] [ state ] [ Discussion Board ]
Title Description
For a set of natural numbers, seeking each interval [a, b] value
Entry
Title plurality of sets of input <10 ^ 6 group
Each row two numbers a, b (0 <a, b <= 10000)
while (~ scanf ( "% d% d", & a, & b)) {} may be read automatically terminate
Export
Input and output each a natural number, and represents
Sample input
186 6907
0 2475
39 3742
127 2546
195 8529
1 485
155 4754
Sample Output
23,839,573 3.06405 million 7002412 3.23433 million 36.35727 million 117 855 11.2907 million
problem solutions: a + ...... + b = ( a + b) * (b-a + 1) / 2
code is as follows
#include<iostream>
using namespace std;
main()
{
int a,b,i,j,k;
while (cin>>a>>b)
{
j=(a+b)*(b-a+1);
k=j/2;
cout << k<<endl;
}
}