Logo
(追記) (追記ここまで)

23458번 - King 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 256 MB86221424.561%

문제

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 $p$. A sequence $(a_1,a_2,\ldots,a_n)$ is a King sequence if and only if there is an integer 1ドル\leq q < p$ such that for all integers $i\in [2,n],ドル $q a_{i-1} \equiv a_i \pmod p$.

Given a sequence $B=(b_1,\ldots,b_m),ドル what is the length of the longest King subsequence of $B$?

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

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

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

입력

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

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

The second line in a test case contains a sequence $b_1,\ldots, b_n$ (1ドル\le b_i< p$).

출력

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

제한

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

예제 출력 1

5
-1
3
-1

힌트

출처

Contest > Open Cup > 2019/2020 Season > Stage 10: Grand Prix of Xi’An H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /