zoj 2836 容斥原理
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2836
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <cstring>
- #include <queue>
- #include <vector>
- #define maxn 15
- #define INF 0x3f3f3f
- using namespace std;
- int a[maxn];
- int N;
- long long ans,M;
- int gcd(int a,int b){ //printf("%d %d\n",a,b);
- if(a%b == ) return b;
- else return gcd(b,a%b);
- }
- int lcm(int a,int b){
- if(a<b){
- int temp = a;
- a = b;
- b = temp;
- }
- return a*b/gcd(a,b);
- }
- void dfs(int u,int deep,int sum){
- for(int i=u+;i<=N;i++){
- int temp = lcm(sum,a[i]);
- if(temp > M) return;
- if(deep%) ans += M/temp;
- else ans -= M/temp;
- dfs(i,deep+,temp);
- }
- }
- int main()
- {
- //freopen("input.txt","r",stdin);
- while(cin>>N>>M){
- for(int i=;i<=N;i++) cin>>a[i];
- sort(a+,a+N+);
- ans = ;
- dfs(,,);
- printf("%lld\n",ans);
- }
- }
zoj 2836 容斥原理的更多相关文章
- [ZOJ 2836] Number Puzzle
Number Puzzle Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...
- ZOJ 2836
求不比M大的可以被集合任一个数整除的数的个数.(容斥原理) #include <iostream> #include <cstdio> #include <algorit ...
- ZOJ 2386 容斥原理
题意:给出n个数,和m(1<=m<=200 000 000),求1~M中能被这n个数其中任意一个数整除的个数: 分析:n范围很小,可以枚举选择被哪些数整除,被奇数个整数整除加m/这个n个数 ...
- 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> ...
- CSU训练分类
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...
- [容斥原理] zoj 3556 How Many Sets I
主题链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4535 How Many Sets I Time Limit: 2 ...
- ZOJ 3233 Lucky Number --容斥原理
这题被出题人给活活坑了,题目居然理解错了..哎,不想多说. 题意:给两组数,A组为幸运基数,B组为不幸运的基数,问在[low,high]区间内有多少个数:至少被A组中一个数整除,并且不被B中任意一个数 ...
- ZOJ 3687 The Review Plan I 容斥原理
一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #inclu ...
- ZOJ 1442 Dinner Is Ready 容斥原理 + java大数
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=442 求解 x1 + x2 + x3 + .... + xn = m 其中xi属 ...
随机推荐
- 给sqlserver配置内存参数
操作环境:windows server 2003 R2 Enterprise Edition SP1 + 4G 内存 + Sqlsever 2005 在以上环境中,运行公司的ERP数据服务,sqlse ...
- ASP.NET mvc 遇见的问题
1.数据库配置 The specified named connection is either not found in the configuration, not intended to be ...
- 用于显示上个月和下个月_PHP
/** * 用于显示上个月和下个月 * @param int $sign 1:表示上个月 0:表示下个月 * @return string */ function GetMonth($sign=&qu ...
- Dell服务器MegaCli命令只返回Exit Code: 0x00问题分析
今天同事给我说一台dell的服务器做了raid后,使用MegaCli看不到raid信息,上去看了一下确实不返回任何raid信息,但是确实机器上做了raid. 这就奇怪了,然后把MegaCli升级到最新 ...
- Xcode的控制台调试命令
XCode4.0以后,编译器换成了LLVM 编译器 2.0 与以前相比,更加强大:1.LLVM 编译器是下一带开源的编译技术.完全支持C, Objective-C, 和 C++.2.LLVM 速度比 ...
- maven+jetty项目在tomcat部署
步骤1:项目打包 clean install 步骤二:拷贝war 包到tomcat下 步骤三:修改server.xml文件的端口 步骤四:启动tomcat,注意jetty的项目是不需要带项目名的,To ...
- SOAPUI请求及mockservice 使用
1.新建soap Project,输入wsdl的地址,运行request 2 ...
- 【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 ...
- javascript——浅谈javascript模版(自定义)
/** * Created by Administrator on 15-1-19. */ function functionUtil() { } functionUtil = { //某个DOM节点 ...
- 关于本地计算机无法启动Apache2
最近因工作需要,要学习PHP的基础编程,于是学习架设PHP工作环境. 但按照教材上介绍的那样,安装了WMAP后,一直无法运行成功.后发现Apache一直都不在运行状态.到WMAP中的Apache选项中 ...