#P9438. 『XYGOI round1』好多数
『XYGOI round1』好多数
Background
X is playing with L. They walked into a park and found a very strange towering tree. Following the habits of OIers, this tree has a clear feature: it is heavily right-skewed.
Problem Description
X thought of another thing that is also heavily right-skewed.
First, he writes down a number .
Next, for every divisor of with , make these become the children of , in increasing order.
Build the tree recursively in this way, and the tree is completed. X calls this tree an “-th mathematical tree”. X wants to know: given positive integers , how many times does each of them appear in the -th mathematical tree.
Since is very large, he can only tell you the prime factorization of .
Output the answers modulo .
Input Format
The first line contains several pairs of integers , meaning that , and ends with 0 0. It is guaranteed that is prime and .
The second line contains one integer , with the meaning as described above.
The third line contains integers, representing the queries for this testdata.
Output Format
Output one line with integers, where each is the answer for the corresponding query modulo .
2 3 3 1 0 0
1
2
8
2 3 3 1 0 0
3
3 5 7
4 0 0
7 3 0 0
3
49 1 343
1 0 1
Hint
Sample explanation: the first two sets of testdata are both the -th mathematical tree. After drawing, the tree is as follows:

Among them, appears times, appears times, and do not appear.
For the third set of testdata, note that appears once at the root of the -th mathematical tree, and will not appear in the mathematical tree.
| Subtask | Guaranteed that is a prime power | Score | ||
|---|---|---|---|---|
| 0 | Yes | 10 | ||
| 1 | No | |||
| 2 | Yes | 40 | ||
| 3 | No |
For of the data, , , , .
Translated by ChatGPT 5