#GL0000386. Đếm tập con theo ước chung lớn nhất (GCD Subsets)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm tập con theo ước chung lớn nhất (GCD Subsets)
GCD Subsets
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers. A non-empty subset selects one or more positions, so equal values at different positions are still distinct choices.
For every , count the non-empty subsets whose elements have GCD exactly . Print the counts modulo .
Input
- First line: the integer .
- Second line: integers .
Output
Print integers. The -th integer counts subsets of GCD modulo .
Subtasks
-
Subtask 1 (20 points): and .
-
Subtask 2 (30 points): and .
-
Subtask 3 (50 points): and .
Examples
Input
5
5 4 4 2 3
Output
22 4 1 3 1
Explanation
There are non-empty subsets. Exactly three subsets have GCD : choose a non-empty subset of the two positions with value . Exactly one subset has GCD . Exactly four have GCD : select the position holding and any subset of the two positions holding . The remaining counts are for GCD and for GCD .