您的位置:首页 > 其它

LightOJ - 1356

2017-07-04 09:12 204 查看
素数+二分图

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

A set of integers is called prime independent if none of its member is a prime multiple of another member. An integer
a 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 contains
N integers separated by a single space. Each of these N integers are distinct and between
1 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

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

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

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

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

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


大概就是这样了

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: