After creating a trivial task in this time's mini competition, Z2505 Railgun Attack. CL decided to go back to his classroom and study M2. In CL’s M2 Class, Mr Lee decided to ask different questions, which he called “Primary School Math” as he always says. The 2 most clever students in the class, George and Edmond the Elephant, decided to have a battle against each other. In the battle, Mr Lee kept making up some problems and challenged the whole class. 9 out of 10 times, the one who answered was Edmond the elephant. (That 1 time was answered by CL, what did u expect). George really wanted to win, so he decided to seek your help, and tell George the correct answers.
In the coming battle, Mr Lee will ask $Q$ questions, with 5 different questions types:
In question type A, Mr Lee needs you to determine whether the number $K$ is a prime number or not.
In question type B, Mr Lee will ask you to provide the answer of $K!$ mod $M$.
In question type C, Mr Lee will ask you to add up $N$ fractions and give the answer in fraction form or improper fraction form (假分數).
In question type D, Mr Lee asks you to provide the maximum and minimum number in the $N$ given numbers, $K$.
In question type E, Mr Lee will require you to answer the greatest common divisor (GCD) and lowest common multiple (LCM) of the $N$ given numbers, $K$.
Please be reminded that cheating is never a good action, and you should never use your phone during class to contact others without the teacher's permission.
Do not copy George.
- Message from Madam Gazelle.
Input
The first line contains a single integer $Q$.
The following $Q$ queries each contain a single character, $C$.
If $C$ = A
:
An integer, $N$, will be given.
If $C$ = B
:
2 integers $K$, $M$ will be given.
If $C$ = C
:
An integer $N$ will be provided in the first line.
In the following $N$ lines, $N$ fractions will be given in the form of a b
.
If $C$ = D
:
An integer $N$ will be provided in the first line.
In the next line, $N$ integers will be given.
If $C$ = E
:
An integer $N$ will be provided in the first line.
In the next line, $N$ integers will be given.
Output
Output each of the following answers to the corresponding question type in $Q$ lines.
If $C$ = A
, output Yes
if the integer is a prime number, No
otherwise.
If $C$ = B
, output 1 integer, the answer of $K!$ mod $M$.
If $C$ = C
, output the fractional form of the answer in the form of a/b
.
If $C$ = D
, output 2 integers, the maximum and minimum number among $N$ integers.
If $C$ = E
, output 2 integers, the GCD and LCM among $N$ integers.
Constraints
For all test cases:
$1 \le Q \le 10^5$
For $C$ = A
: $1 \le K \le 10^5$
For $C$ = B
: $1 \le K \le 10^3$, $1 \le M \le 10^5$
For $C$ = C
: $1 \le N, a, b \le 10^2$, the reduced form of prefix sum of fraction does not contain integers exceeding 64-bit range
For $C$ = D
: $1 \le N \le 10^3$, $0 \le |K| \le10^5$
For $C$ = E
: $1 \le N \le 10^3$, $ 1 \le K \le10^2$
It is guaranteed that the answers are in the range of 64-bit integers.
Subtask 1 (10%): $C$ = A
Subtask 2 (10%): $C$ = B
Subtask 3 (10%): $C$ = C
Subtask 4 (10%): $C$ = D
Subtask 5 (10%): $C$ = E
Subtask 6 (50%): No additional constraints
Sample Test Cases
Input | Output | |
---|---|---|
2 A 13 A 26 |
Yes No |
|
1 B 20 2001 |
954 | |
1 C 2 1 2 3 4 |
5/4 | |
1 D 5 10 -7 9 120 0 |
120 -7 | |
1 E 3 6 12 18 |
6 36 |
Scoring: Per Subtask
Authored by wy23493
Appeared in WYHK 2025 Mini Contest 0 [Session 2] and WYHK 2025 Mini Contest 0