#P13945. [EC Final 2019] King

[EC Final 2019] King

题目描述

As we all know, the number of Pang\textit{Pang}'s papers follows exponential growth. Therefore, we are curious about King\textit{King} sequence.

You are given a prime pp. A sequence (a1,a2,,an)(a_1,a_2,\ldots,a_n) is a King\textit{King} sequence if and only if there is an integer 1q<p1\leq q < p such that for all integers i[2,n]i\in [2,n], qai1ai(modp)q a_{i-1} \equiv a_i \pmod p.

Given a sequence B=(b1,,bm)B=(b_1,\ldots,b_m), what is the length of the longest King\textit{King} subsequence of BB?

A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

PangPang is super busy recently, so the only thing he wants to know is whether the answer is greater than or equal to n2\frac{n}{2}.

If the length of the longest King\textit{King} sequence is less than n2\frac{n}{2}, output 1-1. Otherwise, output the length of the longest King\textit{King} subsequence.

输入格式

The first line contains an integer TT denoting the number of test cases (1T10001\le T\le 1000).

The first line in a test case contains two integers nn and pp (2n2000002\le n \le 200000, 2p10000000072\le p \le 1000000007, pp is a prime). The sum of nn over all test cases does not exceed 200000200000.

The second line in a test case contains a sequence b1,,bnb_1,\ldots, b_n (1bi<p1\le b_i< p).

输出格式

For each test case, output one line containing the answer which is 1-1 or the length of the longest King\textit{King} subsequence.

4
6 1000000007
1 1 2 4 8 16
6 1000000007
597337906 816043578 617563954 668607211 89163513 464203601
5 1000000007
2 4 5 6 8
5 1000000007
2 4 5 6 7
5
-1
3
-1