10783-odd Sum
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem &problem=1724
Given a range [a, b], you are to find the summation of all the odd integers in this range. For example, the summation of the "odd integers in" range [3, 9] is 3 + 5 + 7 + 9 = 24.
Input
There can be at multiple test cases. The "a" of input gives you the number of test cases, T (1t100). Then T test Cases follow. Each test case consists of 2 integers a and b (0ab) I n two separate lines.
Output
For each test case you are are to print one line of output-the serial number of the test case followed by the summation of T He odd integers in the range [a, b].
Sample Input
2
1
5
3
5
Sample Output
Case 1:9 Case
2:8
Complete code:
/*0.006s*/
#include <cstdio>
int main (void)
{
int T, a, B;
scanf ("%d", &t);
for (int i = 1; I <= t; ++i)
{
scanf ("%d%d", &a, &b);
A >>= 1, b = (b + 1) >> 1;
printf ("Case%d:%d\n", I, b * b-a * a);
}
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/