博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B - Number Puzzle ZOJ - 2836(容斥原理 数学)
阅读量:4136 次
发布时间:2019-05-25

本文共 1232 字,大约阅读时间需要 4 分钟。

Given a list of integers (A1, A2, …, An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given list.

Input

The input contains several test cases.

For each test case, there are two lines. The first line contains N (1 <= N <= 10) and M (1 <= M <= 200000000), and the second line contains A1, A2, …, An(1 <= Ai <= 10, for i = 1, 2, …, N).

Output

For each test case in the input, output the result in a single line.

Sample Input

3 2
2 3 7
3 6
2 3 7

Sample Output

1
4
抽空起来整理训练的题目,还是容斥原理.这次看就比原来明白多了…
怎么说呢,感觉容斥原理本质上就是加奇减偶.然后我们根据题意去在这个基础上做一些改变.这个题目的本意是,给你n个数,再给你一个m,找出不大于m,而且至少能被这n个数中一个数整除的数的个数.典型的容斥定理,a+b+c-ab-ac-bc+abc…就是这样奇加偶减.dfs做就可以了.集体解释看代码.
代码如下:

#include
#include
#include
#include
#include
#define ll long longusing namespace std;const int maxx=11;ll n,m,ans;ll vis[maxx];ll b[maxx];int cnt;ll gcd(ll x,ll y)//求gcd,最大公因数{ if(x%y==0) return y; else return gcd(y,x%y);}ll lcm(ll x,ll y)//最小公倍数{ return x/gcd(x,y)*y;}void dfs(ll cur,ll ant,ll num)//ant代表数组下标,防止重复搜索..num代表几个数字..来进行奇加偶减{ if(cur>m||num>cnt) return ; for(int i=ant;i

容斥原理要多思考.推出公式来就好了…

努力加油a啊,(o)/~.

转载地址:http://pzxvi.baihongyu.com/

你可能感兴趣的文章
手绘VS码绘(二):动态图绘制(码绘使用Processing)
查看>>
基于P5.js的“绘画系统”
查看>>
《达芬奇的人生密码》观后感
查看>>
论文翻译:《一个包容性设计的具体例子:聋人导向可访问性》
查看>>
基于“分形”编写的交互应用
查看>>
《融入动画技术的交互应用》主题博文推荐
查看>>
链睿和家乐福合作推出下一代零售业隐私保护技术
查看>>
Unifrax宣布新建SiFAB™生产线
查看>>
艾默生纪念谷轮™在空调和制冷领域的百年创新成就
查看>>
NEXO代币持有者获得20,428,359.89美元股息
查看>>
Piper Sandler为EverArc收购Perimeter Solutions提供咨询服务
查看>>
RMRK筹集600万美元,用于在Polkadot上建立先进的NFT系统标准
查看>>
JavaSE_day14 集合中的Map集合_键值映射关系
查看>>
异常 Java学习Day_15
查看>>
Mysql初始化的命令
查看>>
MySQL关键字的些许问题
查看>>
浅谈HTML
查看>>
css基础
查看>>
Servlet进阶和JSP基础
查看>>
servlet中的cookie和session
查看>>