#GL0000366. Đếm tập con có tích là số chính phương (Square Subsets)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm tập con có tích là số chính phương (Square Subsets)
Square Subsets
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , choose a nonempty subset of indices and multiply the corresponding values. A selection is valid when its product is a perfect square for a positive integer . Two selections differ if their index sets differ, even if the selected values are equal.
Count the valid selections modulo .
Input
- Line 1: the integer .
- Line 2: the integers .
Output
Print the number of nonempty index subsets with a perfect-square product, modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Example 1
Input
4
1 1 1 1
Output
15
Explanation
Every product equals . Among subsets of four positions, exclude the empty subset: remain.
Example 2
Input
4
2 2 2 2
Output
7
Explanation
The number of selected s must be even. There are ways to select two positions and way to select all four, giving .
Example 3
Input
5
1 2 4 5 8
Output
7
Explanation
Value must be excluded. Among , the entries and must either both be selected or both omitted, while and are independent choices. This gives subsets including the empty one, hence .