#P7961. [NOIP2021] 数列
[NOIP2021] 数列
Problem Description
You are given integers , and a positive integer array of length .
For a non-negative integer sequence of length (indexed from ) where each element is at most , we define its weight as $v_{a_1} \times v_{a_2} \times \cdots \times v_{a_n}$.
If such a sequence satisfies that, in the binary representation of the integer , the number of bits is at most , then we call a valid sequence.
Compute the sum of weights of all valid sequences modulo .
Input Format
The first line contains three integers .
The second line contains integers: .
Output Format
Output a single integer, representing the sum of weights of all valid sequences modulo .
5 1 1
2 1
40
见附件中的 sequence/sequence2.in
见附件中的 sequence/sequence2.ans
Hint
[Sample Explanation #1]
Since , and from we know , there is only one possible valid : . This requires that must contain zeros and ones. Therefore, there are possible sequences. Each sequence contributes , so the sum of weights is .
[Constraints]
For all testdata, it is guaranteed that , , and .
::cute-table{tuack}
| Test Point | |||
|---|---|---|---|
| ^ | |||
| ^ | |||
| ^ | |||
| ^ |
Translated by ChatGPT 5