luogu#P8292. [省选联考 2022] 卡牌
[省选联考 2022] 卡牌
Problem Description
Little A has cards, numbered . Each card has a positive integer written on it, and the positive integer on the -th card is .
Now there are rounds of games. In the -th round, primes are given. Little A needs to choose any number of cards such that the product of the positive integers on these chosen cards is divisible by every prime given in that round.
This is not hard for Little A, so he starts thinking about a harder problem: for each round, how many different ways are there to choose cards.
Little A cannot figure it out, so he asks you for help. You only need to output the answer modulo . Two selections and are different if and only if there exists a card that is chosen in but not in , or there exists a card that is chosen in but not in . Note: two cards with the same number written on them but different indices are considered different cards.
Input Format
The first line contains a positive integer , indicating the number of cards.
The second line contains positive integers , indicating the number written on each card.
The third line contains a positive integer , indicating the number of rounds.
The next lines describe the rounds. In each line, the first positive integer is , indicating the number of primes given in that round, followed by primes , indicating all primes given in that round. The testdata guarantees that , i.e., the sum of all does not exceed .
Output Format
Output lines. Each line contains one integer. The -th line is the number of valid selections for the -th round modulo .
5
10 2 10 5 46
4
2 2 5
2 2 23
1 3
1 23
27
16
0
16
见附件中的 card/card2.in
见附件中的 card/card2.ans
Hint
[Sample Explanation #1]
Round 1: Except for the following selections, all other selections are valid: selecting nothing, selecting , selecting , selecting , selecting and . Therefore, the answer is .
Round 2: As long as is selected, it does not matter whether other cards are selected, so the answer is .
[Constraints]
For of the testdata, , , , , .
| Test Point | Other Constraints | |||
|---|---|---|---|---|
| None | ||||
| None | ||||
Translated by ChatGPT 5