UVa 10783 Odd Sum (Water ver.)

Source: Internet
Author: User
Tags time limit

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.