呃,我竟然傻了,同时被a且b整除的个数为n/(a*b)。

其实应该是n/[a,b]才对,是他们的最小公倍数啊。。。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. __int64 ans;
  8. __int64 set[30];
  9. __int64 n;
  10. int m;
  11.  
  12. __int64 gcd(__int64 a,__int64 b){
  13. if(b==0) return a;
  14. return gcd(b,a%b);
  15. }
  16.  
  17. void dfs(int i,int num,__int64 tmp){
  18. if(i>=m){
  19. if(num==0){
  20. ans=0;
  21. }
  22. else {
  23. if(num&1){
  24. ans=(ans+n/tmp);
  25. }
  26. else{
  27. ans=ans-n/tmp;
  28. }
  29. }
  30. return ;
  31. }
  32. dfs(i+1,num,tmp);
  33. dfs(i+1,num+1,tmp*set[i]/gcd(tmp,set[i]));
  34. }
  35.  
  36. int main(){
  37. bool flag;
  38. while(scanf("%I64d%d",&n,&m)!=EOF){
  39. n--;
  40. flag=true;
  41. int k=0;
  42. for(int i=0;i<m;i++){
  43. scanf("%I64d",&set[i]);
  44. if(set[i])
  45. set[k++]=set[i];
  46. }
  47. m=k;
  48. ans=0;
  49. dfs(0,0,1);
  50. printf("%I64d\n",ans);
  51. }
  52. return 0;
  53. }

  

HDU 1796的更多相关文章

  1. HDU 1796 How many integers can you find (状态压缩 + 容斥原理)

    题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...

  2. HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)

    HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...

  3. HDU 1796 容斥原理 How many integers can you find

    题目连接   http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理  纪念一下  TMD看了好久才明白DFS... 先贴代码后解释 #includ ...

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

    题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description    ...

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

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

  6. HDU 1796 容斥原理

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

  7. HDU 1796 How many integers can you find 容斥入门

    How many integers can you find Problem Description   Now you get a number N, and a M-integers set, y ...

  8. hdu 1796 How many integers can you find

    容斥原理!! 这题首先要去掉=0和>=n的值,然后再使用容斥原理解决 我用的是数组做的…… #include<iostream> #include<stdio.h> #i ...

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

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

  10. HDU 1796 (容斥原理)

    容斥原理练习题,忘记处理gcd 和 lcm,wa了几发0.0. #include<iostream> #include<cstdio> #include<cstring& ...

随机推荐

  1. 结束QQ即时通信垄断,开辟即时通信互联互通instantnet时代

    结束QQ即时通信垄断,开辟即时通信互联互通instantnet时代 蓬勃发展的即时通信产业 即时通信(IM)是指可以即时发送和接收互联网消息等的业务. 即时通信.就是瞬间把信息发送给对方,假设不是即时 ...

  2. Linux系统编程——进程替换:exec 函数族

    在 Windows 平台下,我们能够通过双击运行可运行程序,让这个可运行程序成为一个进程.而在 Linux 平台.我们能够通过 ./ 运行,让一个可运行程序成为一个进程. 可是.假设我们本来就执行着一 ...

  3. Spring-SpringJdbcTemlate配置介绍

    使用spring的jdbcTemplate进一步操作JDBC 一.普通配置  SpringJdbcTemplate连接数据库并操作数据 1.applicationContext.xml 1.1 建立D ...

  4. Pixhawk---基于NSH的Firmware开发与调试

    1 相关知识了解 1.1 Nuttx系统   嵌入式实时操作系统(RTOS). 强调标准兼容和小型封装,具有从8位到32位微控制器环境的高度可扩展性.NuttX 主要遵循 Posix 和 ANSI 标 ...

  5. 深刻理解Java中的String、StringBuffer和StringBuilder的差别

    声明:本博客为原创博客,未经同意.不得转载!小伙伴们假设是在别的地方看到的话,建议还是来csdn上看吧(链接为http://blog.csdn.net/bettarwang/article/detai ...

  6. HDU 1113 Word Amalgamation (map 容器 + string容器)

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...

  7. edit filter rules in sql source control

    https://documentation.red-gate.com/soc6/common-tasks/exclude-objects-using-filters 如果有人上传了filter,nam ...

  8. CGContext含义

    代码 含义 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 CGContextMoveToPoint 开始画线 CGContex ...

  9. 知网下载pdf文件的方法

    title: 知网下载pdf文件的方法 toc: false date: 2018-11-02 17:54:43 categories: methods tags: 知网 平时我们使用的是国内版的知网 ...

  10. sdwebimage缓存图片

    当使用SDWebImage时,如果用相同图片名的图片替换掉了原始缓存的图片,当再次请求的时候,还是使用的缓存图片,图片不会发生改变 原因:图片在NSCache中是以absolute url作为key存 ...