LightOJ

来源:互联网 发布:网络语言大全2017 编辑:程序博客网 时间:2024/06/05 16:14

素数+二分图

二分图我不会暂时就不给代码了

A set of integers is called prime independent if none of its member is a prime multiple of another member. An integera is said to be a prime multiple of b if,

a = b x k (where k is a prime [1])

So, 6 is a prime multiple of 2, but 8 is not. And for example, {2, 8, 17} is prime independent but{2, 8, 16} or {3, 6} are not.

Now, given a set of distinct positive integers, calculate the largest prime independent subset.


Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with an integer N (1 ≤ N ≤ 40000) denoting the size of the set. Next line containsN integers separated by a single space. Each of these N integers are distinct and between1 and 500000 inclusive.

Output

For each case, print the case number and the size of the largest prime independent subset.

Sample Input

3

5

2 4 8 16 32

5

2 3 4 6 9

3

1 2 3

Sample Output

Case 1: 3

Case 2: 3

Case 3: 2


题意:给你一串数,求他们最大的质数独立集的长度,质数独立集是一个集合中的所有数两两之间不能通过乘一个素数得到

思路:大概就是建一个二分图来解,二分图需要以两个数之间是否可以通过乘一个素数得到来判断加不加边,关于判断的方法:

给一个数分解质因子,然后分别除以每一个质因子,看得到的那个数是否存在在给的数列中,存在的话这两个数就prime multiple(因为a[i]<=500000,可以存下每一个数是否存在,并且质因子也不多)

然后就是根据质因子数目是奇数还是偶数分成两边,然后根据prime multiple关系连边,然后二分图匹配

不过要注意的是此题时间卡的紧

大概就是这样了

(本人菜的抠脚暂时不会二分图,所以只能这样了)