CF1747E.List Generation
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For given integers n and m, let's call a pair of arrays a and b of integers good, if they satisfy the following conditions:
- a and b have the same length, let their length be k.
- k≥2 and a1=0,ak=n,b1=0,bk=m.
- For each 1<i≤k the following holds: ai≥ai−1, bi≥bi−1, and ai+bi=ai−1+bi−1.
Find the sum of ∣a∣ over all good pairs of arrays (a,b). Since the answer can be very large, output it modulo 109+7.
对于给定的整数 n 和 m,若整数数组对 (a,b) 满足以下条件,则称其为“好”的:
- a 和 b 长度相同,记该长度为 k;
- k≥2,且 a1=0, ak=n, b1=0, bk=m;
- 对每个 1<i≤k,均满足:ai≥ai−1,bi≥bi−1,且 ai+bi=ai−1+bi−1。
求所有“好”的数组对 (a,b) 对应的 ∣a∣(即数组 a 的长度 k)之和。由于答案可能非常大,请输出其对 109+7 取模的结果。
输入格式
The input consists of multiple test cases. The first line contains a single integer t(1≤t≤104) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers n and m (1≤n,m≤5⋅106).
It is guaranteed that the sum of n over all test cases does not exceed 5⋅106 and the sum of m over all test cases does not exceed 5⋅106.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 m(1≤n,m≤5⋅106)。
保证所有测试用例中 n 的总和不超过 5⋅106,且所有测试用例中 m 的总和不超过 5⋅106。
输出格式
For each test case, output a single integer — the sum of ∣a∣ over all good pairs of arrays (a,b) modulo 109+7.
对于每个测试用例,输出一个整数——即所有好数组对 (a,b) 对应的 ∣a∣ 之和,对 109+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]), length = 2.
- ([0,1,1],[0,0,1]), length = 3.
- ([0,0,1],[0,1,1]), length = 3.
Hence the sum of the lengths would be 2+3+3=8.
在第一个测试用例中,满足条件的数组对有:
- ([0,1],[0,1]),长度为 2。
- ([0,1,1],[0,0,1]),长度为 3。
- ([0,0,1],[0,1,1]),长度为 3。
因此,这些长度之和为 2+3+3=8。
输入解题思路,AI测评打分。不知道怎么写?