CF1747E.List Generation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For given integers nn and mm , let's call a pair of arrays aa and bb of integers good, if they satisfy the following conditions:

  • aa and bb have the same length, let their length be kk .
  • k2k \ge 2 and a1=0,ak=n,b1=0,bk=ma_1 = 0, a_k = n, b_1 = 0, b_k = m .
  • For each 1<ik1 < i \le k the following holds: aiai1a_i \geq a_{i - 1} , bibi1b_i \geq b_{i - 1} , and ai+biai1+bi1a_i + b_i \neq a_{i - 1} + b_{i - 1} .

Find the sum of a|a| over all good pairs of arrays (a,b)(a,b) . Since the answer can be very large, output it modulo 109+710^9 + 7 .

输入格式

The input consists of multiple test cases. The first line contains a single integer t(1t104)t (1 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers nn and mm (1n,m5106)(1 \leq n, m \leq 5 \cdot 10^6) .

It is guaranteed that the sum of nn over all test cases does not exceed 51065 \cdot 10^6 and the sum of mm over all test cases does not exceed 51065 \cdot 10^6 .

输出格式

For each test case, output a single integer — the sum of a|a| over all good pairs of arrays (a,b)(a,b) modulo 109+710^9 + 7 .

输入输出样例

  • 输入#1

    4
    1 1
    1 2
    2 2
    100 100

    输出#1

    8
    26
    101
    886336572

说明/提示

In the first testcase, the good pairs of arrays are

  • ([0,1],[0,1])([0, 1], [0, 1]) , length = 22 .
  • ([0,1,1],[0,0,1])([0, 1, 1], [0, 0, 1]) , length = 33 .
  • ([0,0,1],[0,1,1])([0, 0, 1], [0, 1, 1]) , length = 33 .

Hence the sum of the lengths would be 2+3+3=8{2 + 3 + 3} = 8 .

首页