#P9774. [HUSTFC 2023] 新取模运算
[HUSTFC 2023] 新取模运算
Problem Description
In this problem, we define a new operator , called the new modulo operation.
When computing , if is not a multiple of , the result is the remainder of divided by . Otherwise, keep dividing by until is no longer a multiple of . Let it be , and then take the remainder of divided by . For example, , , .
Given a prime , there are multiple queries. In each query, an integer is given, and you need to compute the value of . Here, is the factorial of , i.e. the product of all positive integers less than or equal to .
Input Format
The first line contains two integers and , representing the number of queries and the given prime.
The next lines each contain an integer , with the meaning as described above.
Output Format
For each query, output one line containing one integer, the value of .
3 7
11
45
14
4
1
2
2 10007
1919
810
3152
3679
Hint
Translated by ChatGPT 5