Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.

容斥原理裸题

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll; inline int gcd(int a,int b){
return b?gcd(b,a%b):a;
} int num[]; int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
n--;
for(int i=;i<=m;++i){
scanf("%d",&num[i]);
if(!num[i]){
i--;
m--;
}
}
ll ans=;
for(int i=;i<(<<m);++i){
int bit=;
int tmp=;
for(int j=;j<=m;++j){
if(i&(<<(j-))){
bit++;
tmp=tmp/gcd(tmp,num[j])*num[j];
}
}
if(bit%)ans+=n/tmp;
else ans-=n/tmp;
}
printf("%lld\n",ans);
}
return ;
}

hdu1796 How many integers can you find 容斥原理的更多相关文章

  1. HDU1796 How many integers can you find(容斥原理)

    题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ...

  2. HDU 1796 Howmany integers can you find (容斥原理)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. Hdu1796 How many integers can you find 2017-06-27 15:54 25人阅读 评论(0) 收藏

    How many integers can you find Time Limit : 12000/5000ms (Java/Other)   Memory Limit : 65536/32768K ...

  4. HDU 1796 How many integers can you find(容斥原理)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. hdu1796 How many integers can you find

    //设置m,Q小于n可以设置如何几号m随机多项整除 //利用已知的容斥原理 //ans = 数是由数的数目整除 - 数为整除的两个数的数的最小公倍数 + 由三个数字... #include<cs ...

  6. HDU 1796 How many integers can you find(容斥原理)

    题意 就是给出一个整数n,一个具有m个元素的数组,求出1-n中有多少个数至少能整除m数组中的一个数 (1<=n<=10^18.m<=20) 题解 这题是容斥原理基本模型. 枚举n中有 ...

  7. HDU1796 How many integers can you find【容斥定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包 ...

  8. 容斥原理学习(Hdu 4135,Hdu 1796)

    题目链接Hdu4135 Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. hdu分类 Math Theory(还有三题!)

    这个分类怎么觉得这么水呢.. 这个分类做到尾的模板集: //gcd int gcd(int a,int b){return b? gcd(b, a % b) : a;} //埃氏筛法 O(nlogn) ...

随机推荐

  1. es6新增的math函数有哪些

    Math.trunc():用于去除一个数的小数部分,返回整数部分. Math.sign():用来判断一个数到底是正数.负数.还是零. Math.cbrt():用于计算一个数的立方根. Math.hyp ...

  2. Unity运行错误代码处理

    1.Unity在运行时出现如图错误,但不影响运行效果展示. 2.错误原因:代码不规范. 3.检查代码,查看变量是否定义正确.

  3. Date和 Calendar

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  4. Oracle 12c的自增列Identity Columns

    在Oracle的12c版本中,Oracle实现了类似MySQL中的auto_increment的自增列,下面我们看一起Oracle是怎么实现的. Oracle Database 12c Enterpr ...

  5. 锤子科技 Smartisan M1L 咖啡金 真皮背面 高配版 5.7

    http://www.smartisan.com/m1/#/os    快人一步的OS http://www.smartisan.com/shop/#/buyphone?c=coffee&v= ...

  6. 【转载】Maven中的BOM概念

    1.概述 1.1.什么是 BOM? BOM stands for Bill Of Materials. A BOM is a special kind of POM that is used to c ...

  7. node 慕课笔记

    global global.testVar2 = 200; 在别的文件中可以任意调用到 因为global是全局变量相当于js的window一样的

  8. matlab中的reshape快速理解,卷积和乘积之间的转换

    reshape: THe convertion between convolution and multiplication:

  9. java.lang.String 使用介绍

    这里我们将总结字符串相关的知识,除了总结String的API用法,同时我们还会总结一些相关的知识点,包括字符串常量池.StringBuffer.StringBuilder,以及equals和==的用法 ...

  10. 安装Android开发工具

    这两天开始学Android,首先要要解决的是安装编译器的问题,经过我这两天的探究,我把收获总结一下 最简单的编译器是ADT-bundle,它是一个集成的工具,里面有eclipse,也不需要下载SDK, ...