A15558 | List Generation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 \ge 2$ and $a_1 = 0, a_k = n, b_1 = 0, b_k = m$ .
- For each $1 < i \le k$ the following holds: $a_i \geq a_{i - 1}$ , $b_i \geq b_{i - 1}$ , and $a_i + b_i \neq a_{i - 1} + b_{i - 1}$ .
Find the sum of $|a|$ over all good pairs of arrays $(a,b)$ . Since the answer can be very large, output it modulo $10^9 + 7$ .
- $a$ and $b$ have the same length, let their length be $k$ .
- $k \ge 2$ and $a_1 = 0, a_k = n, b_1 = 0, b_k = m$ .
- For each $1 < i \le k$ the following holds: $a_i \geq a_{i - 1}$ , $b_i \geq b_{i - 1}$ , and $a_i + b_i \neq a_{i - 1} + b_{i - 1}$ .
Find the sum of $|a|$ over all good pairs of arrays $(a,b)$ . Since the answer can be very large, output it modulo $10^9 + 7$ .
输入格式
The input consists of multiple test cases. The first line contains a single integer $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 $n$ and $m$ $(1 \leq n, m \leq 5 \cdot 10^6)$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^6$ and the sum of $m$ over all test cases does not exceed $5 \cdot 10^6$ .
The only line of each test case contains two integers $n$ and $m$ $(1 \leq n, m \leq 5 \cdot 10^6)$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^6$ and the sum of $m$ over all test cases does not exceed $5 \cdot 10^6$ .
输出格式
For each test case, output a single integer — the sum of $|a|$ over all good pairs of arrays $(a,b)$ modulo $10^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])$ , 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])$ , 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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted