CF1371B.Magical Calendar
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days!
In detail, she can choose any integer k which satisfies 1≤k≤r, and set k days as the number of days in a week.
Alice is going to paint some n consecutive days on this calendar. On this calendar, dates are written from the left cell to the right cell in a week. If a date reaches the last day of a week, the next day's cell is the leftmost cell in the next (under) row.
She wants to make all of the painted cells to be connected by side. It means, that for any two painted cells there should exist at least one sequence of painted cells, started in one of these cells, and ended in another, such that any two consecutive cells in this sequence are connected by side.
Alice is considering the shape of the painted cells. Two shapes are the same if there exists a way to make them exactly overlapped using only parallel moves, parallel to the calendar's sides.
For example, in the picture, a week has 4 days and Alice paints 5 consecutive days. [1] and [2] are different shapes, but [1] and [3] are equal shapes.

Alice wants to know how many possible shapes exists if she set how many days a week has and choose consecutive n days and paints them in calendar started in one of the days of the week. As was said before, she considers only shapes, there all cells are connected by side.
一位竞食选手爱丽丝正在为一场竞食比赛在一张魔法日历上安排一些训练。这张日历很特别,因为一周并不一定包含 7 天!
具体来说,她可以选择任意满足 1≤k≤r 的整数 k,并将 k 设为一周的天数。
爱丽丝将在该日历上连续涂画 n 天。在此日历中,日期从每周最左侧的格子开始向右依次书写;若某日期到达一周的最后一天,则下一日将写在下一行(正下方)最左侧的格子中。
她希望所有被涂画的格子在边相邻的意义下是连通的。也就是说,对任意两个被涂画的格子,都应存在至少一条由被涂画格子构成的序列,该序列起始于其中一个格子、终止于另一个格子,且序列中任意两个相邻格子均边相邻。
爱丽丝关注的是所涂画格子形成的形状。若仅通过平行于日历边界的平移操作即可使两个形状完全重合,则认为这两个形状相同。
例如,在下图中,一周有 4 天,爱丽丝涂画了 5 个连续的日期。[1] 和 [2] 是不同的形状,但 [1] 和 [3] 是相同的形状。

爱丽丝想知道:当她选定一周的天数(即选定 k)、并在日历上从某一天开始连续涂画 n 天时,总共能形成多少种互不相同的形状?如前所述,她只考虑所有格子边相邻连通的形状。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.
For each test case, the only line contains two integers n, r (1≤n≤109,1≤r≤109).
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。接下来的 t 行描述了各个测试用例。
对于每个测试用例,唯一的一行包含两个整数 n 和 r(1≤n≤109, 1≤r≤109)。
输出格式
For each test case, print a single integer — the answer to the problem.
Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language.
对于每个测试用例,输出一个整数——即该问题的答案。
请注意,某些测试用例的答案无法用 32 位整数类型表示,因此在编程语言中至少应使用 64 位整数类型。
输入输出样例
输入#1
5 3 4 3 2 3 1 13 7 1010000 9999999
输出#1
4 3 1 28 510049495001
说明/提示
In the first test case, Alice can set 1,2,3 or 4 days as the number of days in a week.
There are 6 possible paintings shown in the picture, but there are only 4 different shapes. So, the answer is 4. Notice that the last example in the picture is an invalid painting because all cells are not connected by sides.

In the last test case, be careful with the overflow issue, described in the output format.
在第一个测试用例中,Alice 可以将一周的天数设为 1、2、3 或 4 天。
图中展示了 6 种可能的涂色方案,但仅有 4 种不同的形状。因此答案为 4。注意:图中最后一个示例是一种无效的涂色方案,因为所有格子并未通过边相连。

在最后一个测试用例中,请注意输出格式中描述的溢出问题。
输入解题思路,AI测评打分。不知道怎么写?