Odd GCD Matching
Time limit1sMemory limit512 MB
Given N integers, find the largest set of disjoint pairs where each pair has an odd greatest common divisor.
- Level
Medium7 of 10
- Topics
- Number theory, Graph, Greedy, Math
- Solved
- No attempts yet
Problem
There are integers . can be paired with if is odd. is the greatest common divisor of and . For example, 6 can be paired with 9 because is odd; however, 12 cannot be paired with 8 because is even.
An odd GCD matching of is a set of pairs satisfying the following.
- Each pair consists of two integers with .
- Each integer appears at most once in the set.
- If is in the set, then can be paired with .
Given , find the size of a maximum odd GCD matching of . An odd GCD matching is maximum if and only if no other odd GCD matching has more pairs than it.
For example, let . The size of a maximum odd GCD matching in this example is 2; one such matching is , which pairs with and with . Note that with size 1 is also a valid odd GCD matching, but it is not maximum. On the other hand, is not a valid odd GCD matching because cannot be paired with in this example.
Input
The first line contains an integer , the size of . () The next line contains integers , the array . ()
Output
Output in one line an integer, the size of a maximum odd GCD matching of .