#P5676. [GZOI2017] 小z玩游戏

    ID: 4626 远端评测题 1500ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论2017各省省选O2优化贵州Tarjan

[GZOI2017] 小z玩游戏

Description

Little z is very bored.

Little z wants to play games.

Little z has NN new games. The apparent fun level of the ii-th game is wiw_i.

Little z is picky. He will only play a game whose apparent fun level is an integer multiple of his excitement level.

Since some games are actually fun and some are not, after finishing the ii-th game, Little z’s excitement level will become eie_i.

It is known that Little z’s initial excitement level is 11. Please determine how many games Little z might play twice.

Input Format

The first line contains a positive integer TT, indicating the number of testdata groups, up to 1010 groups.

For each group of testdata:

  • The first line contains a positive integer NN, indicating the number of games.
  • The second line contains NN positive integers. The ii-th number wiw_i indicates that the apparent fun level of the ii-th game is wiw_i.
  • The third line contains NN positive integers. The ii-th number eie_i indicates that after Little z finishes the ii-th game, his excitement level will become eie_i.

Output Format

Output TT lines in total.

Each line contains one positive integer, indicating for the corresponding testdata group, the number of games that Little z might play twice.

5
1
100000
100000
5
1 2 6 15 35
5 7 9 2 3
5
2 3 5 35 21
7 11 7 3 2
10
6 15 77 12 24 37 35 99 55 42
4 2 5 7 11 3 6 8 9 10
10
6540 5604 567 57065 60 670 6870 1230 465 6540
12 5 37 3 34 13 17 18 10 12
1
3
3
8
5

Hint

Explanation for Sample 2

Numbers represent game indices, and arrows indicate the next one.

  • Case 11: 25422\to 5\to 4\to 2.
  • Case 22: 54255\to 4\to 2\to 5.
  • Case 33: 42544\to 2\to 5\to 4.

So Little z might play games 2,4,52,4,5 twice.

No matter what, Little z cannot play game 11 or 33 twice.

Constraints

Translated by ChatGPT 5