No.2394 Sum of Subsequence-Sum Powers
Problem Statement
You are given three positive integers $N, M, B$ and a sequence $A$ of $N$ positive integers as input.
First, we introduce some notation. Let $S(A)$ be the set of all subsequences of $A$ (not necessarily contiguous).
Here, a subsequence also includes the data of which positions of $A$ its elements were taken from.
For example, when $A = (1,1,2)$, $A$ has $2$ subsequences that are $(1,2)$ as sequences, and they are distinguished from each other.
For each subsequence $A'$ of $A$, let $s(A')$ be the sum of its elements.
Find the remainder when $\sum_{A' \in S(A)} M^{s(A')}$ is divided by $B$.
Input
The input is given from standard input in $2$ lines in the following format:
$N$ $M$ $B$ $A$
- Line $1$ contains $N, M, B$, separated by single-byte spaces.
- Line $2$ contains the elements of $A$, separated by single-byte spaces.
Constraints
The input satisfies the following constraints:
- $N$ is an integer satisfying $1 \leq N \leq 10^5$
- $M$ is an integer satisfying $1 \leq M \leq 10^{18}$
- $B$ is an integer satisfying $1 \leq B \leq 10^9$
- Each element $a$ of $A$ is an integer satisfying $1 \leq a \leq 10^{18}$
Output
Print the remainder when $\sum_{A' \in S(A)} M^{s(A')}$ is divided by $B$ on $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
1 1 2 1
Output
0
$A = (1)$ has $2$ subsequences: the subsequence $A'_0$, which as a sequence is the empty sequence $()$, and the subsequence $A'_1$, which as a sequence is $(1)$.
$\displaystyle \sum_{A' \in S(A)} M^{s(A')} = M^{s(A'_0)} + M^{s(A'_1)} = 1^0 + 1^1 = 1 + 1 = 2 $
and the remainder when $2$ is divided by $B = 2$ is $0$.
Sample 2
Input
1 2 2 1
Output
1
$A$ is the same as in Sample 1. Using the same notation as in Sample 1, we have
$\displaystyle \sum_{A' \in S(A)} M^{s(A')} = M^{s(A'_0)} + M^{s(A'_1)} = 2^0 + 2^1 = 1 + 2 = 3 $
and the remainder when $3$ is divided by $B = 2$ is $1$.
Sample 3
Input
2 1 2 1 3
Output
0
$A = (1,3)$ has $4$ subsequences: the subsequence $A'_0$, which as a sequence is the empty sequence $()$, the subsequence $A'_1$, which as a sequence is $(1)$, the subsequence $A'_2$, which as a sequence is $(3)$, and the subsequence $A'_3$, which as a sequence is $(1,3)$.
$\displaystyle \sum_{A' \in S(A)} M^{s(A')} = M^{s(A'_0)} + M^{s(A'_1)} + M^{s(A'_2)} + M^{s(A'_3)} = 1^0 + 1^1 + 1^3 + 1^4 = 1 + 1 + 1 + 1 = 4 $
and the remainder when $4$ is divided by $B = 2$ is $0$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
hotman78