Save the country!

0

0 votes
Medium
Problem

On the occasion of Diwali one of the terrorist group , Group A aim to get support from the another group, Group B and plan a attack on your city. Being ACP of the city you need to break their connection and save the city. Each terrorist is given a rank based upon his skill. A terrorist from either group can connect to another group terrorist if the rank of terrorist from group A is a factor of rank of other terrorist. You have to break the connection by killing N1 number of terrorist from group A and N2 number of terrorist from group B. Minimizing (N1 + N2) you have to disconnect both the groups. 

By killing a terrorist you break all connection associated with it.

 

INPUT

  • First Line contains a integer T, denoting number of testcases. Description of each test case is as follows.
  •  First line of each test case contains two space seperated integers N and M , where N denotes the number of terrorist in group A and group B  respectively.
  • Next two lines contains N and M space seperated integers and ith value of each line denotes rank of the ith terrorist of the group.

OUTPUT

For each test case print the minimum value of (N1+ N2).

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Ranks of Terorist in Group A = {2, 3, 4, 5}

Ranks of Terrorist in Group B = {6, 7, 8, 9}

On killing terrorist of rank 2, 3 from Set A and 8 from set B we get new sets as {4, 5} and {6, 7,9}. So none of the ranks of group A i.e {4, 5} is  a factor of ranks of terrorist of Group B. ( You saved the City!)

Editor Image

?