题意:给出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. esper(4-5)- Context 条件

    条件主要包含:Filter,Pattern,Crontab以及Time Period Filter主要就是对属性值的过滤,比如: create context NewUser partition by ...

  2. oracle 备份恢复篇(一)---rman

    一,rman介绍 RMAN(Recovery Manager)是随Oracle服务器软件一同安装的工具软件,它可以用来备份和恢复数据库文件.归档日志和控制文件,用来执行完全或不完全的数据库恢复.与传统 ...

  3. Dubbo解析及原理浅析

    原文链接:https://blog.csdn.net/chao_19/article/details/51764150 一.Duboo基本概念解释 Dubbo是一种分布式服务框架. Webservic ...

  4. Java基础21-构造函数之间的调用

    public class Test{ public static void main(String[] args){ Persion p2=new Persion("小明",22) ...

  5. 接口隔离原则(Interface Segregation Principle)ISP

    using System; using System.Collections.Generic; using System.Text; namespace InterfaceSegregationPri ...

  6. Ace教你一步一步做Android新闻客户端(一)

    复制粘贴了那么多博文很不好意思没点自己原创的也说不出去,现在写一篇一步一步教你做安卓新闻客户端,借此机会也是让自己把相关的技术再复习一遍,大神莫笑,专门做给新手看. 手里存了两篇,一个包括软件视图 和 ...

  7. Beam编程系列之Apache Beam WordCount Examples(MinimalWordCount example、WordCount example、Debugging WordCount example、WindowedWordCount example)(官网的推荐步骤)

    不多说,直接上干货! https://beam.apache.org/get-started/wordcount-example/ 来自官网的: The WordCount examples demo ...

  8. Spring3.2下使用JavaMailSenderImpl类发送邮件

    1.JavaMailSenderImpl类 Spring的邮件发送的核心是MailSender接口,在Spring3.0中提供了一个实现类JavaMailSenderImpl,这个类是发送邮件的核心类 ...

  9. RestTemplate请求出现401错误

    最近遇到一个请求API接口总是报401 Unauthorized错误,起初是认为这个是平台返回的,后来用Postman请求,发现平台其实返回的是一串json,里面带有一些权限验证失败的消息,但到我们代 ...

  10. oracle 常用操作记录--持续更新...

    一.oracle grant 授权语句(转自:https://www.cnblogs.com/yt954437595/p/6488819.html) --select * from dba_users ...