题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2836

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <cstring>
  6. #include <queue>
  7. #include <vector>
  8.  
  9. #define maxn 15
  10. #define INF 0x3f3f3f
  11. using namespace std;
  12.  
  13. int a[maxn];
  14. int N;
  15. long long ans,M;
  16. int gcd(int a,int b){ //printf("%d %d\n",a,b);
  17. if(a%b == ) return b;
  18. else return gcd(b,a%b);
  19. }
  20. int lcm(int a,int b){
  21. if(a<b){
  22. int temp = a;
  23. a = b;
  24. b = temp;
  25. }
  26. return a*b/gcd(a,b);
  27. }
  28. void dfs(int u,int deep,int sum){
  29. for(int i=u+;i<=N;i++){
  30. int temp = lcm(sum,a[i]);
  31. if(temp > M) return;
  32. if(deep%) ans += M/temp;
  33. else ans -= M/temp;
  34. dfs(i,deep+,temp);
  35. }
  36. }
  37.  
  38. int main()
  39. {
  40. //freopen("input.txt","r",stdin);
  41. while(cin>>N>>M){
  42. for(int i=;i<=N;i++) cin>>a[i];
  43. sort(a+,a+N+);
  44. ans = ;
  45. dfs(,,);
  46. printf("%lld\n",ans);
  47. }
  48. }

zoj 2836 容斥原理的更多相关文章

  1. [ZOJ 2836] Number Puzzle

    Number Puzzle Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...

  2. ZOJ 2836

    求不比M大的可以被集合任一个数整除的数的个数.(容斥原理) #include <iostream> #include <cstdio> #include <algorit ...

  3. ZOJ 2386 容斥原理

    题意:给出n个数,和m(1<=m<=200 000 000),求1~M中能被这n个数其中任意一个数整除的个数: 分析:n范围很小,可以枚举选择被哪些数整除,被奇数个整数整除加m/这个n个数 ...

  4. ZOJ 2836 Number Puzzle 题解

    题面 lcm(x,y)=xy/gcd(x,y) lcm(x1,x2,···,xn)=lcm(lcm(x1,x2,···,xn-1),xn) #include <bits/stdc++.h> ...

  5. CSU训练分类

    √√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...

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

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

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

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

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

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

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

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

随机推荐

  1. 给sqlserver配置内存参数

    操作环境:windows server 2003 R2 Enterprise Edition SP1 + 4G 内存 + Sqlsever 2005 在以上环境中,运行公司的ERP数据服务,sqlse ...

  2. ASP.NET mvc 遇见的问题

    1.数据库配置 The specified named connection is either not found in the configuration, not intended to be ...

  3. 用于显示上个月和下个月_PHP

    /** * 用于显示上个月和下个月 * @param int $sign 1:表示上个月 0:表示下个月 * @return string */ function GetMonth($sign=&qu ...

  4. Dell服务器MegaCli命令只返回Exit Code: 0x00问题分析

    今天同事给我说一台dell的服务器做了raid后,使用MegaCli看不到raid信息,上去看了一下确实不返回任何raid信息,但是确实机器上做了raid. 这就奇怪了,然后把MegaCli升级到最新 ...

  5. Xcode的控制台调试命令

    XCode4.0以后,编译器换成了LLVM 编译器 2.0 与以前相比,更加强大:1.LLVM 编译器是下一带开源的编译技术.完全支持C, Objective-C, 和 C++.2.LLVM 速度比 ...

  6. maven+jetty项目在tomcat部署

    步骤1:项目打包 clean install 步骤二:拷贝war 包到tomcat下 步骤三:修改server.xml文件的端口 步骤四:启动tomcat,注意jetty的项目是不需要带项目名的,To ...

  7. SOAPUI请求及mockservice 使用

    1.新建soap Project,输入wsdl的地址,运行request                                                               2 ...

  8. 【POJ2886】【线段树】Who Gets the Most Candies?

    Description N children are sitting in a circle to play a game. The children are numbered from 1 to N ...

  9. javascript——浅谈javascript模版(自定义)

    /** * Created by Administrator on 15-1-19. */ function functionUtil() { } functionUtil = { //某个DOM节点 ...

  10. 关于本地计算机无法启动Apache2

    最近因工作需要,要学习PHP的基础编程,于是学习架设PHP工作环境. 但按照教材上介绍的那样,安装了WMAP后,一直无法运行成功.后发现Apache一直都不在运行状态.到WMAP中的Apache选项中 ...