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.

容斥原理裸题

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #include<math.h>
  5. using namespace std;
  6. typedef long long ll;
  7.  
  8. inline int gcd(int a,int b){
  9. return b?gcd(b,a%b):a;
  10. }
  11.  
  12. int num[];
  13.  
  14. int main(){
  15. int n,m;
  16. while(scanf("%d%d",&n,&m)!=EOF){
  17. n--;
  18. for(int i=;i<=m;++i){
  19. scanf("%d",&num[i]);
  20. if(!num[i]){
  21. i--;
  22. m--;
  23. }
  24. }
  25. ll ans=;
  26. for(int i=;i<(<<m);++i){
  27. int bit=;
  28. int tmp=;
  29. for(int j=;j<=m;++j){
  30. if(i&(<<(j-))){
  31. bit++;
  32. tmp=tmp/gcd(tmp,num[j])*num[j];
  33. }
  34. }
  35. if(bit%)ans+=n/tmp;
  36. else ans-=n/tmp;
  37. }
  38. printf("%lld\n",ans);
  39. }
  40. return ;
  41. }

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. Java工厂方法模式

    工厂方法模式: /** * 工厂方法模式:也叫工厂模式,属于创建型模式,父类工厂(接口)负责定义产品对象的公共接口, * 而子类工厂负责创建具体的产品对象. * 目的:是为了把产品的实例化操作延迟到子 ...

  2. 【转载】 unity 塔防游戏

    原文地址: Part1的地址:http://www.cnblogs.com/lcxBlog/p/6075984.html Part2的地址:http://www.cnblogs.com/lcxBlog ...

  3. node 慕课笔记

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

  4. ubuntu多显示器单触摸屏校准

    多显示器单触摸屏屏幕校准 0.触摸屏重定向 sudo xinput map-to-output 13 DP1  #将触摸屏映射到指定的显示器 其中:13为触摸屏设备id,可通过 xinput命令查看 ...

  5. 更改centos源为aliyun

    完全参考 http://mirrors.aliyun.com/help/centos?spm=5176.bbsr150321.0.0.d6ykiD 1.备份 mv /etc/yum.repos.d/C ...

  6. Java语法基础学习DayEight

    一.异常处理 1.结构 java.lang.Object |-----java.lang.Throwable |-----java.lang.Error:错误,java程序对此无能为力,不显式处理 | ...

  7. JavaWeb:一个Servelt多个请求

    一个Servelt多个请求 基础模拟 方法一:使用switch方法  一.方法介绍 方法:switch 优点:方法简单,明了 缺点:维护麻烦,保密性不好 二.代码实现 1.servlet类 packa ...

  8. 解决jsp表达式不能解析的问题

    在jsp页面用了表达式,但是出现了表达式不能解析的问题 出现的页面如下 原因:web.xml的版本过低,maven自动生成的web.xml版本为2.3,只有2.3以上的版本才支持表达式 解决方法:改w ...

  9. Day14作业及默写

    1.整理今天所学内容,整理知识点,整理博客. pass 2.画好流程图. pass 3.都完成的做一下作业(下面题都是用内置函数或者和匿名函数结合做出): pass 4.用map来处理字符串列表,把列 ...

  10. day12作业