CF1747E.List Generation

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

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.
  • k≥2k \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<i≤k1 \lt i \le k the following holds: ai≥ai−1a_i \geq a_{i - 1}, bi≥bi−1b_i \geq b_{i - 1}, and ai+bi≠ai−1+bi−1a_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.

对于给定的整数 nn 和 mm,若整数数组对 (a,b)(a, b) 满足以下条件,则称其为“好”的:

  • aa 和 bb 长度相同,记该长度为 kk;
  • k≥2k \ge 2,且 a1=0, ak=n, b1=0, bk=ma_1 = 0,\ a_k = n,\ b_1 = 0,\ b_k = m;
  • 对每个 1<i≤k1 \lt i \le k,均满足:ai≥ai−1a_i \geq a_{i - 1},bi≥bi−1b_i \geq b_{i - 1},且 ai+bi≠ai−1+bi−1a_i + b_i \neq a_{i - 1} + b_{i - 1}。

求所有“好”的数组对 (a,b)(a,b) 对应的 ∣a∣|a|(即数组 aa 的长度 kk)之和。由于答案可能非常大,请输出其对 109+710^9 + 7 取模的结果。

输入格式

The input consists of multiple test cases. The first line contains a single integer t(1≤t≤104)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 (1≤n,m≤5⋅106)(1 \leq n, m \leq 5 \cdot 10^6).

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

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 mm(1≤n,m≤5⋅1061 \leq n, m \leq 5 \cdot 10^6)。

保证所有测试用例中 nn 的总和不超过 5⋅1065 \cdot 10^6,且所有测试用例中 mm 的总和不超过 5⋅1065 \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.

对于每个测试用例,输出一个整数——即所有好数组对 (a,b)(a,b) 对应的 ∣a∣|a| 之和,对 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.

在第一个测试用例中,满足条件的数组对有:

  • ([0,1],[0,1])([0, 1], [0, 1]),长度为 22。
  • ([0,1,1],[0,0,1])([0, 1, 1], [0, 0, 1]),长度为 33。
  • ([0,0,1],[0,1,1])([0, 0, 1], [0, 1, 1]),长度为 33。

因此,这些长度之和为 2+3+3=8{2 + 3 + 3} = 8。

输入解题思路,AI测评打分。不知道怎么写?

首页