Sherlock and Coprime Subset
Practice
4.5 (31 votes)
Algorithms
Approved
Bit manipulation
Dynamic programming
Medium
Open
Problem
59% Success 2957 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Recently Watson learned the concept of coprime numbers and now he wonders given an array A1, A2 . . . AN what is the size of the largest subset of the array such that the each pair of elements in the subset is coprime.
Watson asks Sherlock for help and in turn Sherlock needs you.
Input
First line contains T, the number of test cases.
Each test case contains N in one line, number of elements in the array.
Next line contains N space separated elements A1, A2 . . . AN.
Output
For each test case, output the required answer in one line.
Constraints:
1 ≤ T ≤ 10
25% test data: 1 ≤ N ≤ 10
75% test data: 1 ≤ N ≤ 50
1 ≤ Ai ≤ 50
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
AlgorithmsDynamic ProgrammingMedium
Points:30
14 votes
Tags:
AlgorithmsBit ManipulationDynamic ProgrammingMedium
Points:30
14 votes
Tags:
AlgorithmsApprovedBit ManipulationDynamic ProgrammingMedium
Editorial