#P8980. 「DROI」Round 1 游戏

    ID: 9986 远端评测题 1000~2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学洛谷原创O2优化素数判断,质数,筛法

「DROI」Round 1 游戏

Background

In life, isn’t everything also a game?

Problem Description

You will play TT games with a child. The rules of each game are as follows:

  1. First, you need to choose a positive integer xx in [1,n][1,n].

  2. Next, the child will make QQ queries. For each query, he will give an aia_i (guaranteed that ai[1,n]a_i \in [1,n]), and you need to answer the value of gcd(x,ai)\gcd(x,a_i).

  3. After the child gets the answer in some round, if he can uniquely determine the number you chose, then this game ends.

Now you know in advance the aia_i for each query. You need to find an xx such that the game lasts for as many rounds as possible.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, indicating the number of games.

For each game:

The first line contains two integers nn and QQ.

The second line contains QQ integers, where the ii-th integer represents aia_i.

Output Format

For each game, output the maximum number of rounds the game can last. If there exists an xx such that the child still cannot uniquely determine its value after QQ rounds, output game won't stop.

1
11 3
8 9 5
game won't stop
2
8 5
8 2 3 5 7 
24 16
3 17 18 5 19 4 16 23 7 11 13 18 6 21 22 2

5
11

Hint

Sample Explanation #1

Choose 1111 as xx. Obviously, the child cannot uniquely determine xx until the end of the game.


Sample Explanation #2

For the first test case: choose 11 as xx. The child can uniquely determine xx after the fifth round ends. It can be proven that no better xx exists.

For the second test case: similarly, choosing 11 as xx is enough.


Constraints

"This problem uses bundled testdata."

  • Subtask1(20%)\operatorname{Subtask} 1(20\%): n,Q500n,Q\leq 500.

  • Subtask2(20%)\operatorname{Subtask} 2(20\%): n,Q5×104n,Q \leq 5 \times 10^4.

  • Subtask3(30%)\operatorname{Subtask} 3(30\%): Q105Q \leq 10^5.

  • Subtask4(30%)\operatorname{Subtask} 4(30\%): no special restrictions.

For 100%100\% of the data: T10T \leq 10, 1ain10181 \leq a_i \leq n \leq 10^{18}, 1Q2×1061 \leq Q \leq 2\times 10^{6}, Q6×106\sum Q \leq 6\times 10^{6}.

The input size is large, so please use a faster input method.

Translated by ChatGPT 5