#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 nn.

Next, for every divisor xx of nn with x{1,n}x\notin\{1,n\}, make these xx become the children of nn, in increasing order.

Build the tree recursively in this way, and the tree is completed. X calls this tree an “nn-th mathematical tree”. X wants to know: given qq positive integers xx, how many times does each of them appear in the nn-th mathematical tree.

Since nn is very large, he can only tell you the prime factorization of nn.

Output the answers modulo 998244353998244353.

Input Format

The first line contains several pairs of integers (ai,bi)(a_i,b_i), meaning that n=aibin=\prod a_i^{b_i}, and ends with 0 0. It is guaranteed that aia_i is prime and biNb_i\in N^*.

The second line contains one integer qq, with the meaning as described above.

The third line contains qq integers, representing the qq queries for this testdata.

Output Format

Output one line with qq integers, where each is the answer for the corresponding query modulo 998244353998244353.

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 2424-th mathematical tree. After drawing, the tree is as follows:

Among them, 22 appears 88 times, 33 appears 44 times, and 5,75,7 do not appear.

For the third set of testdata, note that 343343 appears once at the root of the 343343-th mathematical tree, and 11 will not appear in the mathematical tree.

Subtask nn qq Guaranteed that nn is a prime power Score
0 103\le 10^3 20\le 20 Yes 10
1 106\le 10^6 No
2 bi5000\sum b_i\le5000 Yes 40
3 No

For 100%100\% of the data, 1bi50001\le b_i \le 5000, bi5000\sum b_i\le5000, 2ai1092\le a_i\le 10^9, 1x10181\le x\le 10^{18}.

Translated by ChatGPT 5