文理学院程序设计在线练习


Gauss in Elementary School

Time Limit: 1 Second(s)    Memory Limit: 32 MB

Total Submission(s): 43   Accepted Submission(s): 22
Problem Description

Johann Carl Friedrich Gauss(1777–1855) was one of the most important German mathematicians. For those of you who remember the Deutsche Mark, a picture of him was printed on the 10 DM bill. In elementaryschool, his teacher tried to occupy the pupils by making them add up the integers from 1 to 100. The young Gauss surprised everybody by producing the correct answers (5050) within seconds.
Can you write a computer program that can compute such sums really quickly?

Given two integers n and m, you should compute the sum of all the integers from n to m. In other words,you should compute


Input

The first line contains the number of scenarios(<1000). Each scenario consists of a line containing the numbers n and m (−10^9 <= n <= m <=10^9).

Output

The output for every scenario begins with a line containing “Case #i: ”, where i is the number of the scenario starting at 1. Then print the sum of all integers from n to m.

Sample Input
3
1 100
-11 10
-89173 938749341
Sample Output
Case #1: 5050
Case #2: -11
Case #3: 440625159107385260
Source

武汉大学第二届“e鸣杯”程序设计竞赛2008