If N numbers are divided into two groups and the product of the respective groups is calculated. Out of the different groups, only the groups whose product gcd is 1 are to be picked. get the number of ways in which this can be done...
Note: The two groups cannot be empty. Since the output can be very large print it modulo 10^9+7. Also, remember the two groups are different which should be clear from sample test cases and the demonstration as follows:
e.g. there are 3 numbers as {2,3,5}
1. Group 1: {2, 3}; Product = 6
Group 2: {5}
gcd(6, 5) = 1
The problem is to find the number of ways of dividing the dummies into groups such that the gcd of their product is 1. For the given set of dummies, there are 6 ways of dividing them into two groups following the property.
2. Group 1: {2}
Group 2: {3, 5}
. Group 1: {2, 5}
Group 2: {3}
4. Group 1: {3}
Group 2: {2, 5}
. Group 1: {2, 5}
Group 2: {3}
4. Group 1: {3}
Group 2: {2, 5}
3. Group 1: {2, 5}
Group 2: {3}
4. Group 1: {3}
Group 2: {2, 5}
5. Group 1: {3, 5}
Group 2: {2}
6. Group 1: {5}
Group 2: {2, 3}
more test cases for clarity:
Sample TestCase 1
Input
2 (number of test cases)
3
2 3 4
4
2 4 6 8
Output
2
0Explanation
Test Case 1: There are two ways in which the dummies can be divided into two groups following the property.
Group 1 : {2, 4}; Group 2 : {3}
Group 1 : {3}; Group 2 : {2, 4}
Test Case 2: It is not possible to divide the dummies into two groups following the property.
Answers
Answered by
13
Answer:
share with me today and tomorrow
Similar questions