Interesting Problem容斥原理

Interesting Problem

Description

Dearway knows some people like math problems but other not. Now the fact is in front of you all.
Give n integers x1 x2 ... xn, you should count how many integers from 1 to m that can be divided by at least one of them
.

Input

The first line is an integer T which shows the number of cases.
Then T cases follow. Each case contains 2 lines:
The first line has 2 integers n and m.
The second line contains n integers.
(0 < n < 11, 0 < m < 2^31, 0 < xi < 100)

Output

For each case print the answer in a single line.

Sample Input

2
1 10
3
2 20
3 5

 

Sample Output

3
9

 

Source

题意是给出n个数an,询问1到m至少可以被其中一个数整除的个数

利用容斥原理解,用二进制或DFS确定项

aUbUc...Uz=a+b+c+..+z-anb-anc-......

a=m/ai

anb=lcm(a,b),anbnc..nz=lcm(a,b,c...z)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值