Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)
F
Hamed and AghaBalaSar
Codeforces
2800
原题
← EG1 →
翻译中…

Hamid wrote $3014$ lines of code for the a+b problem and gave $10$ lines of it to Hamed; then the following problem came to Hamed's mind.

翻译中…

You are given two integers $n$ and $m$.

翻译中…

An array $a_1,a_2,\ldots,a_n$ is called snake if and only if all of the following conditions hold:

翻译中…
  • All elements in $a$ are integers between $0$ and $m$;
  • $a_1 + a_2 + \cdots + a_n = m$;
  • $a_n=\max\left([a_1, a_2, \ldots, a_n]\right)$.
翻译中…

We define $f(a)$ as in the following pseudocode:

翻译中…

function f(array a):
    pos := 1
    res := 0
    let nxt[x] be an array such that nxt[x] is the smallest index y such that
                                    y > x and a[y] > a[x],
                              or undefined if no such y exists
    while pos < n:
        if a[pos] < a[n]:
            res += a[nxt[pos]] - a[pos]
            pos := nxt[pos]
        else:
            pos += 1
    return res

翻译中…

Find the sum of $f(a)$ over all snake arrays $a_1,a_2,\ldots,a_n$, modulo $10^9+7$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^5$, $0 \leq m \leq 2 \cdot 10^5$) — the length of a snake array and the sum of all elements in a snake array.

翻译中…

It is guaranteed that the sum of $m$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the sum of $f(a)$ over all snake arrays $a_1,a_2,\ldots,a_n$, modulo $10^9+7$.

翻译中…

Note

翻译中…

In the first test case, there are three snake arrays:

翻译中…
  • $f([0, 5]) = 5$;
  • $f([1, 4]) = 3$;
  • $f([2, 3]) = 1$.
翻译中…

Thus, the answer is $5+3+1=9$.

翻译中…

In the second test case, there are six snake arrays:

翻译中…
  • $f([0, 0, 4]) = 4$;
  • $f([0, 1, 3]) = 3$;
  • $f([1, 0, 3]) = 2$;
  • $f([1, 1, 2]) = 1$;
  • $f([0, 2, 2]) = 2$;
  • $f([2, 0, 2]) = 2$.
翻译中…

Thus, the answer is $4+3+2+1+2+2=14$.

翻译中…

In the fifth test case, a possible snake array is:

翻译中…
  • $f([3, 1, 4, 1, 5, 9]) = 6$.
翻译中…

样例

Input #1
8
2 5
3 4
4 6
5 10
6 23
100 100
142857 33333
200000 0
Output #1
9
14
76
985
142112
771227753
865580631
0
InputCopy OutputCopy
题目信息
题号
2127F
时间限制
2 s
内存限制
512 MB
标签
暴力
组合数学
动态规划
数学
概率论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。