## 程序设计在线评测（Online Judge）

2017年湖南科技大学大学生计算机程序设计竞赛初定于12月17日举行！有意参赛请加QQ群“湖科大程序设计校赛群（369699377）”

[提交][状态][讨论版]

## 题目描述

Give two integers n and m, you should compute the sum of all the integers form n to m. In other words, you should compute:

SUM(n,m) = n + (n + 1) + (n + 2) + … + (m - 1) + m

## 输入

The first line contains the numbers of  cases.  Each case consists of a line containing the numbers n and m,  (-231<n<=m<231)

## 输出

For each case, output SUM(n,m) in one line. followed by a blank line. You may assume the result will be in the range of 64-bit signed integer.

## 样例输入

3
1 100
-11 10
-89173 938749341


## 样例输出

5050

-11

440625159107385260



## 提示

Q: How to use 64-bit integer types ?

A: Server supports signed and unsigned 64-bit integers.

• Signed 64-bit integer. Value range: -9223372036854775808 .. 9223372036854775807.

 Compiler GCC/G++ Pascal Visual C++ 6.0 Visual Studio 2005/2008/2010/2012/2013 Type name long long int64 __int64 long long or __int64 Input scanf("%lld", &x); or cin >> x; read(x); scanf("%I64d", &x); scanf("%lld", &x); or scanf("%I64d", &x); Output printf("%lld", x); cout << x; write(x); printf("%I64d", x); printf("%lld", x); or printf("%I64d", x);

• Unsigned 64-bit integer. Value range: 0 .. 18446744073709551615.

 Compiler GCC/G++ Pascal Visual C++ 6.0 Visual Studio 2005/2008/2010/2012/2013 Type name unsigned long long qword unsigned __int64 unsigned long long or unsigned __int64 Input scanf("%llu", &x); or cin >> x; read(x); scanf("%I64u", &x); scanf("%llu", &x); or scanf("%I64u", &x); Output printf("%llu", x); or cout << x; write(x); printf("%I64u", x); printf("%llu", x); or printf("%I64u", x);

Q How can I read input data until the end of file ?

A You can do it for example like this:

 Language C C++ Pascal To read numbers int n; while(scanf("%d", &n) != EOF) { ... } int n; while (cin >> n) { ... } var n: integer; ... while not seekeof do begin read(n); ... end; To read characters int c; while ((c = getchar()) != EOF) { ... } char c; while (cin.get(c)) { ... } var c: char; ... while not eof do begin read(c); ... end; To read lines char line[1024]; while(gets(line)) { ... } string line; while (getline(cin, line)) { ... } var line: string; ... while not eof do begin readln(line); ... end;

[提交][状态][讨论版]