Count Coprime Subsequences
Practice
2.8 (4 votes)
Combinatorics
Dynamic programming
Basic programming
Number theory
Math
Inclusion Exclusion
Problem
60% Success 432 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code
A sequence
Given an Array
Input Format:
- First line contains an integer
denoting the number of test cases. - First line of each testcase contains an integer
denoting length of . - Next line contains
space-seperated integer, denoting the elements of .
Output Format:
- For each testcase, In a single line, print the number of non-empty co-prime subsequence of the array, modulo
.
Constraints:
Sample Input
5 4 1 1 1 1 5 2 4 6 8 10 6 1 2 3 4 5 6 7 1 2 4 6 8 10 12 8 1 2 2 2 2 2 2 1
Sample Output
15 5 43 13 27
Explanation
- In first test case, every non-empty subsequence is co-prime, thus
subsequences. - In second test case, only length 1 subsequences ie. 5 subsequences are co-prime, every other subsequence has common factor of
between adjacent elements. - In fourth test case, coprime subsequences are all length 1 subsequences and
, thus subsequences. - In fifth test case, the number of co-prime subsequences are,
(1-length), then 6 times, 6 times and 6 times, and , thus subsequences.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
ApprovedDepth First SearchInclusion ExclusionInclusion exclusion principleMathMediumMobius Function
Points:50
1 votes
Tags:
AlgorithmsOpenApprovedHard
Points:30
40 votes
Tags:
CombinatoricsInclusion-exclusionAlgorithmsMath
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor