题意:给出n个数,和m(1<=m<=200 000 000),求1~M中能被这n个数其中任意一个数整除的个数;

分析:n范围很小,可以枚举选择被哪些数整除,被奇数个整数整除加m/这个n个数的公共最小公倍数;

 #include <bits/stdc++.h>

 using namespace std;
int n,m,a[];
int gcd (int a,int b) {
return b==? a:gcd(b,a%b);
} int lcm(int a,int b) {
return a*b/gcd(a,b);
} int multiple(int x,int* cnt) {
int res = ;
*cnt = ;
for(int i=;i<n;i++) {
if(x&(<<i)) {
(*cnt)++;
res = lcm(res,a[i]);
}
}
return res;
} int main()
{ while(scanf("%d%d",&n,&m)!=EOF) {
int ans = ;
for(int i=;i<n;i++)
scanf("%d",&a[i]);
int k;
for(int i=;i<(<<n);i++) {
int lcms = multiple(i,&k);
if(k&) ans+= m/lcms;
else ans-=m/lcms;
}
printf("%d\n",ans);
} return ;
}

ZOJ 2386 容斥原理的更多相关文章

  1. zoj 2836 容斥原理

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2836 #include <cstdio> #incl ...

  2. [容斥原理] zoj 3556 How Many Sets I

    主题链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4535 How Many Sets I Time Limit: 2 ...

  3. ZOJ 3233 Lucky Number --容斥原理

    这题被出题人给活活坑了,题目居然理解错了..哎,不想多说. 题意:给两组数,A组为幸运基数,B组为不幸运的基数,问在[low,high]区间内有多少个数:至少被A组中一个数整除,并且不被B中任意一个数 ...

  4. ZOJ 3687 The Review Plan I 容斥原理

    一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #inclu ...

  5. ZOJ 1442 Dinner Is Ready 容斥原理 + java大数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=442 求解 x1 + x2 + x3 + .... + xn = m 其中xi属 ...

  6. zoj.3868.GCD Expectation(数学推导>>容斥原理)

    GCD Expectation Time Limit: 4 Seconds                                     Memory Limit: 262144 KB    ...

  7. ACM学习历程—ZOJ 3868 GCD Expectation(莫比乌斯 || 容斥原理)

    Description Edward has a set of n integers {a1, a2,...,an}. He randomly picks a nonempty subset {x1, ...

  8. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  9. ZOJ 3687 The Review Plan I

    The Review Plan I Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origi ...

随机推荐

  1. cotex_A7/A9:

    A7与A9的比较:A7计算性能(DMIPS)不如A9(编号越大计算能力越强),但A7功耗更先进,作为A15的协处理器.A8是单核.

  2. Python归纳 | 爬虫基础知识

    1. urllib模块库 Urllib是python内置的HTTP请求库,urllib标准库一共包含以下子包: urllib.error 由urllib.request引发的异常类 urllib.pa ...

  3. hadoop-2.6.0.tar.gz + spark-1.6.1-bin-hadoop2.6.tgz的集群搭建(单节点)(CentOS系统)

    福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑         Java全栈大联盟   ...

  4. opensuse install oracle 11gR2 Error in invoking target 'agent nmhs' of makefile '../ins_emagent.mk'

    转自 http://blog.csdn.net/ly5156/article/details/6647563 遭遇Error in invoking target 'agent nmhs' of ma ...

  5. c#委托、泛型、反射的使用情况

    委托:当你传递的参数不是 变量 时,想把一个方法作为参数传递,此时委托就可以做到这点 泛型:当你传递的参数是一个类时,此时用泛型 反射:都说反射是一种耗时的操作,但是却很有用,所以反射他不是拿来滥用的 ...

  6. tomcat8.5.8遇到的两个问题

    压力测试场景,前端nginx反向代理到4个tomcat实例,在其中的一个实例上产生了大量的countDownConnection Incorrect connection count警告 WARNIN ...

  7. .net mvc 设置div的动态部分视图内容 dynamic partial view

    示例效果:点击按钮,在div中 显示不同的partial view的内容 $("#btnEdit").click(function () { //动态获取相应的部分视图 var u ...

  8. Nginx下载安装

    系统环境:win7 nginx:1.11.4 1.下载Nginx 下载地址:http://nginx.org/en/download.html 2.将压缩包解压到相应位置 3.启动nginx服务,ng ...

  9. POI Excel解析

    Maven 引入POI <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi&l ...

  10. Resharper 的快捷键

      编辑   Ctrl + Space 代码完成 Ctrl + Shift + Space代码完成 Ctrl + Alt + Space代码完成 Ctrl + P 显示参数信息 Alt + Inser ...