#P10030. 「Cfz Round 3」Change

    ID: 10884 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学洛谷原创Special JudgeO2优化洛谷月赛

「Cfz Round 3」Change

Problem Description

Given a prime number pp and three integers a,b,ca, b, c, you need to perform operations on an integer xx that is initially 00. In each operation, you may choose one of the following two types:

  • Type 1 operation: set xx to (x×a)modp(x \times a) \bmod p.
  • Type 2 operation: set xx to (x+b)modp(x + b) \bmod p.

Here, mod\bmod denotes the modulo operation.

You need to determine whether it is possible to obtain cc after a positive number of operations. If possible, output Yes, otherwise output No.

In this problem, the output is case-insensitive. That is, yes, yeS, yEs, Yes, YEs, YeS, yES, Yes are all considered Yes, and similarly for No.

Input Format

This problem contains multiple test cases.

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

Then for each test case, one line contains four integers p,a,b,cp, a, b, c.

Output Format

For each test case, output one line:

  • If cc can be obtained after a positive number of operations, output Yes.
  • Otherwise, output No.

In this problem, the output is case-insensitive. That is, yes, yeS, yEs, Yes, YEs, YeS, yES, Yes are all considered Yes, and similarly for No.

3
5 2 1 4
3 2 2 1
7 2 0 3
Yes
Yes
No

Hint

"Sample Explanation #1"

For the 11st test case, perform the Type 2 operation once and then perform the Type 1 operation twice.

For the 22nd test case, perform the Type 2 operation once and then perform the Type 1 operation once.

For the 33rd test case, it can be proven that no matter how you operate, you cannot obtain 33.

"Constraints"

For all test cases, 1T1001 \le T \le 100, 0a,b,c<p1090 \le a, b, c < p \le 10^9. It is guaranteed that pp is prime.

You can get the score for this problem only if you pass all test points.

Translated by ChatGPT 5