luogu#P8178. 「EZEC-11」Sequence

「EZEC-11」Sequence

Problem Description

Given a sequence ff that satisfies fn=anfn1+bn (n1)f_n = a_n f_{n-1} + b_n \ (n \ge 1).

Determine whether there exists a non-negative integer f0f_0 such that for all 1ik1 \le i \le k, fif_i is a multiple of the prime pip_i.

Input Format

This problem contains multiple test cases.

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

For each test case:

  • The first line contains an integer kk.
  • The second line contains kk integers a1,a2,,aka_1, a_2, \dots, a_k.
  • The third line contains kk integers b1,b2,,bkb_1, b_2, \dots, b_k.
  • The fourth line contains kk integers p1,p2,,pkp_1, p_2, \dots, p_k, and it is guaranteed that pp is prime.

Output Format

For each test case:

  • Output one string per line. If there exists an f0f_0 that satisfies the conditions, output Yes; otherwise, output No.
2
3
1 1 1
2 2 2
3 5 7
3
1 1 1
2 2 2
3 3 3
Yes
No

Hint

[Sample 1 Explanation]

For the first test case, one feasible solution is f0=1f_0 = 1. In this case, f1=3,f2=5,f3=7f_1 = 3, f_2 = 5, f_3 = 7.

For the second test case, there is no f0f_0 that satisfies the conditions.

[Constraints and Notes]

This problem uses bundled tests.

  • Subtask 1 (10 points): k=1k = 1.
  • Subtask 2 (20 points): k2k \le 2.
  • Subtask 3 (20 points): k5k \le 5, pi20p_i \le 20.
  • Subtask 4 (50 points): no special constraints.

For 100%100\% of the testdata: 1T101 \le T \le 10, 1k1031 \le k \le 10^3, 0ai,bi1090 \le a_i, b_i \le 10^9, 2pi1092 \le p_i \le 10^9, and pp is prime.

Translated by ChatGPT 5