Problem:
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:
- X=A1B1×A2B2×…×ANBN (each Ai is prime, each Bi is positive, and A1<A2<…<AN)
- Y=C1D1×C2D2×…×CMDM (each Cj is prime, each Dj is positive, and C1<C2<…<CM)
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 LCM(p,q)=X and GCD(p,q)=Y. Since the answer can be very big, output the answer modulo 998244353.
Notes:
- LCM(p,q) is the smallest positive integer that is simultaneously divisible by p and q.
- GCD(p,q) is the biggest positive integer that simultaneously divides p and q.
Input Format:
The first line contains a single integer N (1≤N≤105) — the number of distinct primes in the prime factorisation of X.
The second line contains N integers A1,A2,A3,…,AN (2≤A1<A2<…<AN≤2⋅106; each Ai is prime) — the primes in the prime factorisation of X.
The third line contains N integers B1,B2,B3,…,BN (1≤Bi≤105) — the exponents in the prime factorisation of X.
The fourth line contains a single integer M (1≤M≤105) — the number of distinct primes in the prime factorisation of Y.
The fifth line contains M integers C1,C2,C3,…,CM (2≤C1<C2<…<CM≤2⋅106; each Cj is prime) — the primes in the prime factorisation of Y.
The sixth line contains M integers D1,D2,D3,…,DM (1≤Dj≤105) — the exponents in the prime factorisation of Y.
Output Format:
An integer representing the number of pairs of positive integers p and q such that LCM(p,q)=X and GCD(p,q)=Y, modulo 998244353.
Note:
In the first example, the integers are as follows:
- X=22×31×51×72=2940
- Y=31×71=21
The following are all possible pairs of p and q:
- p=21, q=2940
- p=84, q=735
- p=105, q=588
- p=147, q=420
- p=420, q=147
- p=588, q=105
- p=735, q=84
- p=2940, q=21
In the third example, the integers are as follows:
- X=21×51=10
- Y=21×31=6
There is no pair p and q that simultaneously satisfies LCM(p,q)=10 and GCD(p,q)=6.