Preparando MOJI
On the trip to campus during the mid semester exam period, Chaneka thinks of two positive integers $$$X$$$ and $$$Y$$$. Since the two integers can be very big, both are represented using their prime factorisations, such that:
Chaneka ponders about these two integers for too long throughout the trip, so Chaneka's friend commands her "Gece, deh!" (move fast) in order to not be late for the exam.
Because of that command, Chaneka comes up with a problem, how many pairs of positive integers $$$p$$$ and $$$q$$$ such that $$$\text{LCM}(p, q) = X$$$ and $$$\text{GCD}(p, q) = Y$$$. Since the answer can be very big, output the answer modulo $$$998\,244\,353$$$.
Notes:
The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 10^5$$$) — the number of distinct primes in the prime factorisation of $$$X$$$.
The second line contains $$$N$$$ integers $$$A_1, A_2, A_3, \ldots, A_N$$$ ($$$2 \leq A_1 < A_2 < \ldots < A_N \leq 2 \cdot 10^6$$$; each $$$A_i$$$ is prime) — the primes in the prime factorisation of $$$X$$$.
The third line contains $$$N$$$ integers $$$B_1, B_2, B_3, \ldots, B_N$$$ ($$$1 \leq B_i \leq 10^5$$$) — the exponents in the prime factorisation of $$$X$$$.
The fourth line contains a single integer $$$M$$$ ($$$1 \leq M \leq 10^5$$$) — the number of distinct primes in the prime factorisation of $$$Y$$$.
The fifth line contains $$$M$$$ integers $$$C_1, C_2, C_3, \ldots, C_M$$$ ($$$2 \leq C_1 < C_2 < \ldots < C_M \leq 2 \cdot 10^6$$$; each $$$C_j$$$ is prime) — the primes in the prime factorisation of $$$Y$$$.
The sixth line contains $$$M$$$ integers $$$D_1, D_2, D_3, \ldots, D_M$$$ ($$$1 \leq D_j \leq 10^5$$$) — the exponents in the prime factorisation of $$$Y$$$.
An integer representing the number of pairs of positive integers $$$p$$$ and $$$q$$$ such that $$$\text{LCM}(p, q) = X$$$ and $$$\text{GCD}(p, q) = Y$$$, modulo $$$998\,244\,353$$$.
4 2 3 5 7 2 1 1 2 2 3 7 1 1
8
2 1299721 1999993 100000 265 2 1299721 1999993 100000 265
1
2 2 5 1 1 2 2 3 1 1
0
In the first example, the integers are as follows:
The following are all possible pairs of $$$p$$$ and $$$q$$$:
In the third example, the integers are as follows:
There is no pair $$$p$$$ and $$$q$$$ that simultaneously satisfies $$$\text{LCM}(p,q)=10$$$ and $$$\text{GCD}(p,q)=6$$$.