题库练习 Game of the Year
← 上一题 下一题 →

A15749 | Game of the Year

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Monocarp and Polycarp are playing a computer game. This game features $n$ bosses for the playing to kill, numbered from $1$ to $n$ .

They will fight each boss the following way:

- Monocarp makes $k$ attempts to kill the boss;
- Polycarp makes $k$ attempts to kill the boss;
- Monocarp makes $k$ attempts to kill the boss;
- Polycarp makes $k$ attempts to kill the boss;
- ...

Monocarp kills the $i$ -th boss on his $a_i$ -th attempt. Polycarp kills the $i$ -th boss on his $b_i$ -th attempt. After one of them kills the $i$ -th boss, they move on to the $(i+1)$ -st boss. The attempt counters reset for both of them. Once one of them kills the $n$ -th boss, the game ends.

Find all values of $k$ from $1$ to $n$ such that Monocarp kills all bosses.

输入格式

The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of testcases.

The first line of each testcase contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of bosses.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le n$ ) — the index of attempt Monocarp kills each boss on.

The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ( $1 \le b_i \le n$ ) — the index of attempt Polycarp kills each boss on.

The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$ .

输出格式

For each testcase, print two lines. The first line should contain a single integer $\mathit{cnt}$ — the number of values of $k$ from $1$ to $n$ such that Monocarp kills all bosses. The second line should contain $\mathit{cnt}$ distinct integers — the values of $k$ themselves.

输入输出样例

输入 #1
3
3
1 1 1
2 3 1
1
1
1
4
1 4 3 2
3 3 4 1
输出 #1
3
1 2 3 
1
1 
2
2 4
C++ 编辑器
输入
输出