#P10030. 「Cfz Round 3」Change
「Cfz Round 3」Change
Problem Description
Given a prime number and three integers , you need to perform operations on an integer that is initially . In each operation, you may choose one of the following two types:
- Type 1 operation: set to .
- Type 2 operation: set to .
Here, denotes the modulo operation.
You need to determine whether it is possible to obtain 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 , representing the number of test cases.
Then for each test case, one line contains four integers .
Output Format
For each test case, output one line:
- If 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 st test case, perform the Type 2 operation once and then perform the Type 1 operation twice.
For the nd test case, perform the Type 2 operation once and then perform the Type 1 operation once.
For the rd test case, it can be proven that no matter how you operate, you cannot obtain .
"Constraints"
For all test cases, , . It is guaranteed that is prime.
You can get the score for this problem only if you pass all test points.
Translated by ChatGPT 5