C - Divisibility Homomorphism Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 11001100

問題文

正整数の無限列 (a1,a2,)(a_1,a_2,\cdots) が以下の条件をともに満たすとき、またそのときに限りそれを 良い と呼びます。

  • ある有限の定数 CC が存在し、すべての 1n1 \le n について anCna_n \le C \cdot n である。
  • すべての正整数の組 (n,m)(n,m) に対し、anama_n \mid a_mnmn\mid m とは同値である。ここで、xyx \mid yxxyy を割り切ることを表す。

長さ NN の整数列 A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N) が与えられます。 (A1,A2,,AN)(A_1,A_2,\cdots,A_N) で始まる良い無限列が存在するか判定してください。

解くべきテストケースは TT 個あります。

制約

  • 1T50001\le T \le 5000
  • 1N50001 \leq N \leq 5000
  • 1Ai10181 \leq A_i \leq 10^{18}
  • ひとつの入力の中のテストケースすべてにわたる NN の総和は 50005000 以下である。
  • すべての入力値は整数である。

入力

入力は標準入力から以下の形式で与えられる。

TT
case1case_1
case2case_2
\vdots
caseTcase_T

各テストケースは以下の形式で与えられる。

NN
A1A_1 A2A_2 \cdots ANA_N

出力

各テストケースについて、(A1,A2,,AN)(A_1,A_2,\cdots,A_N) で始まる良い無限数列が存在するなら Yes、そうでないなら No と出力せよ。
Yes または No の出力において、各文字は大文字・小文字のいずれでもよい。


入力例 1Copy

Copy
5
5
1 2 3 4 5
5
1 4 9 16 25
5
1 4 6 8 10
5
1 2 4 4 5
5
1 2 3 5 4

出力例 1Copy

Copy
Yes
Yes
Yes
No
No

11 番目のテストケースについて、an=na_n=n とでき、これは条件を満たします。

Score : 11001100 points

Problem Statement

We call an infinite sequence of positive integers (a1,a2,)(a_1,a_2,\cdots) good if and only if it satisfies both of the following conditions:

  • There exists a finite constant CC such that anCna_n \le C \cdot n for all 1n1 \le n;

  • For all pairs of positive integers (n,m)(n,m), anama_n \mid a_m if and only if nmn\mid m. Here, xyx \mid y means xx divides yy.

You are given a positive integer sequence A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N) of length NN. Check if there exists a good infinite sequence starting with (A1,A2,,AN)(A_1,A_2,\cdots,A_N).

You have TT testcases to solve.

Constraints

  • 1T50001\le T \le 5000
  • 1N50001 \leq N \leq 5000
  • 1Ai10181 \leq A_i \leq 10^{18}
  • The sum of NN across the test cases in a single input is at most 50005000.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

TT
case1case_1
case2case_2
\vdots
caseTcase_T

Each test case is given in the following format:

NN
A1A_1 A2A_2 \cdots ANA_N

Output

For each test case, if there exists a good infinite sequence starting with (A1,A2,,AN)(A_1,A_2,\cdots,A_N), print Yes, and otherwise print No. In printing Yes or No, you can output each letter in any case (upper or lower).


Sample Input 1Copy

Copy
5
5
1 2 3 4 5
5
1 4 9 16 25
5
1 4 6 8 10
5
1 2 4 4 5
5
1 2 3 5 4

Sample Output 1Copy

Copy
Yes
Yes
Yes
No
No

For the 11-st test case, we can let an=na_n=n and that satisfies the condition.



2025-04-05 (Sat)
06:54:56 +00:00