#P8292. Card Selection for Divisibility
Card Selection for Divisibility
Card Selection for Divisibility
You are given n cards numbered from $$1,2,\ldots,n$$. The i-th card contains a positive integer $$s_i$$.
There are m rounds of games. In the i-th round, you are given $$c_i$$ prime numbers. Your task is to choose an arbitrary subset of cards (possibly empty) such that the product of the numbers on the chosen cards is divisible by each of the given primes. Two selections are considered different if there is at least one card chosen in one selection and not in the other. Note that cards with the same number but different indices are considered distinct.
Output the number of valid selections modulo $$998244353$$ for each round.
inputFormat
The first line contains a single integer $$n$$, the number of cards.
The second line contains $$n$$ positive integers $$s_1,s_2,\ldots,s_n$$.
The third line contains a single integer $$m$$, the number of rounds.
For each round, the first number is an integer $$c_i$$ followed by $$c_i$$ prime numbers separated by spaces.
outputFormat
For each round, output one line containing the number of valid card selections modulo $$998244353$$.
sample
3
2 3 6
2
1 2
2 2 3
6
5
</p>