아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

King

시간 제한2초메모리 제한256 MB

요약
고정된 승수를 곱한 값이 소수 p에 대한 나머지로 이어지는 가장 긴 부분수열의 길이를 구하고, n/2보다 짧으면 -1을 출력한다.
난이도

보통10점 중 6점

유형
수학, 해시맵, 정수론
정답자
아직 제출이 없습니다

문제

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

You are given a prime pp. A sequence (a_1,a_2,…,a_n)(a\_1,a\_2,\ldots,a\_n) is a King sequence if and only if there is an integer 1≤q<p1\leq q < p such that for all integers i∈\[2,n]i\in \[2,n], qa_i−1≡a_i(modp)q a\_{i-1} \equiv a\_i \pmod p.

Given a sequence B=(b_1,…,b_m)B=(b\_1,\ldots,b\_m), what is the length of the longest 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 sequence is less than n2\frac{n}{2}, output −1-1. Otherwise, output the length of the longest King subsequence.

입력

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

The first line in a test case contains two integers nn and pp (2≤n≤2000002\le n \le 200000, 2≤p≤10000000072\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 b_1,…,b_nb\_1,\ldots, b\_n (1≤b_i<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 subsequence.

예제1

  1. 예제 1

    입력
    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