102623: [AtCoder]ABC262 D - I Hate Non-integer Number

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

You are given a sequence of positive integers $A=(a_1,\ldots,a_N)$ of length $N$.
There are $(2^N-1)$ ways to choose one or more terms of $A$. How many of them have an integer-valued average? Find the count modulo $998244353$.

Constraints

  • $1 \leq N \leq 100$
  • $1 \leq a_i \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$a_1$ $\ldots$ $a_N$

Output

Print the answer.


Sample Input 1

3
2 6 2

Sample Output 1

6

For each way to choose terms of $A$, the average is obtained as follows:

  • If just $a_1$ is chosen, the average is $\frac{a_1}{1}=\frac{2}{1} = 2$, which is an integer.

  • If just $a_2$ is chosen, the average is $\frac{a_2}{1}=\frac{6}{1} = 6$, which is an integer.

  • If just $a_3$ is chosen, the average is $\frac{a_3}{1}=\frac{2}{1} = 2$, which is an integer.

  • If $a_1$ and $a_2$ are chosen, the average is $\frac{a_1+a_2}{2}=\frac{2+6}{2} = 4$, which is an integer.

  • If $a_1$ and $a_3$ are chosen, the average is $\frac{a_1+a_3}{2}=\frac{2+2}{2} = 2$, which is an integer.

  • If $a_2$ and $a_3$ are chosen, the average is $\frac{a_2+a_3}{2}=\frac{6+2}{2} = 4$, which is an integer.

  • If $a_1$, $a_2$, and $a_3$ are chosen, the average is $\frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3}$, which is not an integer.

Therefore, $6$ ways satisfy the condition.


Sample Input 2

5
5 5 5 5 5

Sample Output 2

31

Regardless of the choice of one or more terms of $A$, the average equals $5$.

Input

题意翻译

已知一个长度为 $N$ 的数列 $a_1,a_2,\cdots a_N$,从数列中选出至少一个数,使选出的数平均数为整数,求有多少种这样的方案。

Output

得分:400分

问题描述

给你一个长度为 N 的正整数序列 A=(a_1,\ldots,a_N)。
有 $(2^N-1)$ 种方式从 A 中选择一个或多个项。其中有多少种选择的项的平均值是整数?求这个计数对 $998244353$ 取模的结果。

约束条件

  • $1 \leq N \leq 100$
  • $1 \leq a_i \leq 10^9$
  • 输入中的所有值都是整数。

输入

从标准输入以以下格式获取输入:

$N$
$a_1$ $\ldots$ $a_N$

输出

打印答案。


样例输入 1

3
2 6 2

样例输出 1

6

对于从 A 中选择项的每种方式,平均值如下所示:

  • 如果只选择 $a_1$,则平均值为 $\frac{a_1}{1}=\frac{2}{1} = 2$,这是一个整数。

  • 如果只选择 $a_2$,则平均值为 $\frac{a_2}{1}=\frac{6}{1} = 6$,这是一个整数。

  • 如果只选择 $a_3$,则平均值为 $\frac{a_3}{1}=\frac{2}{1} = 2$,这是一个整数。

  • 如果选择 $a_1$ 和 $a_2$,则平均值为 $\frac{a_1+a_2}{2}=\frac{2+6}{2} = 4$,这是一个整数。

  • 如果选择 $a_1$ 和 $a_3$,则平均值为 $\frac{a_1+a_3}{2}=\frac{2+2}{2} = 2$,这是一个整数。

  • 如果选择 $a_2$ 和 $a_3$,则平均值为 $\frac{a_2+a_3}{2}=\frac{6+2}{2} = 4$,这是一个整数。

  • 如果选择 $a_1$、$a_2$ 和 $a_3$,则平均值为 $\frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3}$,这不是一个整数。

因此,有 $6$ 种方式满足条件。


样例输入 2

5
5 5 5 5 5

样例输出 2

31

无论从 A 中选择一个或多个项,平均值都是 5。

加入题单

算法标签: