hdu1796 How many integers can you find 容斥原理
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 容斥原理的更多相关文章
- HDU1796 How many integers can you find(容斥原理)
		题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ... 
- HDU 1796 Howmany integers can you find (容斥原理)
		How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ... 
- 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 ... 
- 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 ... 
- hdu1796 How many integers can you find
		//设置m,Q小于n可以设置如何几号m随机多项整除 //利用已知的容斥原理 //ans = 数是由数的数目整除 - 数为整除的两个数的数的最小公倍数 + 由三个数字... #include<cs ... 
- HDU 1796 How many integers can you find(容斥原理)
		题意 就是给出一个整数n,一个具有m个元素的数组,求出1-n中有多少个数至少能整除m数组中的一个数 (1<=n<=10^18.m<=20) 题解 这题是容斥原理基本模型. 枚举n中有 ... 
- HDU1796 How many integers can you find【容斥定理】
		题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包 ... 
- 容斥原理学习(Hdu 4135,Hdu 1796)
		题目链接Hdu4135 Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ... 
- hdu分类 Math Theory(还有三题!)
		这个分类怎么觉得这么水呢.. 这个分类做到尾的模板集: //gcd int gcd(int a,int b){return b? gcd(b, a % b) : a;} //埃氏筛法 O(nlogn) ... 
随机推荐
- javascript void函数
			<a href="javascript:doTest2();void(0);">here</a> 但这儿的void(0)究竟是何含义呢? Javascrip ... 
- 随机生成id
			function getRandom(){ return Math.random().toString(36).substring(7);} 
- Cracking The Coding Interview 9.3
			//Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log ... 
- 依赖倒置(DIP)、控制反转(IOC)和依赖注入(DI)
			原文: https://blog.csdn.net/briblue/article/details/75093382 写这篇文章的原因是这两天在编写关于 Dagger2 主题的博文时,花了大量的精力来 ... 
- 谷歌开源的TensorFlow Object Detection API视频物体识别系统实现(二)[超详细教程] ubuntu16.04版本
			本节对应谷歌开源Tensorflow Object Detection API物体识别系统 Quick Start步骤(一): Quick Start: Jupyter notebook for of ... 
- easyui再学习的一部分代码
			<%-- Created by IntelliJ IDEA. User: zhen Date: // Time: : To change this template use File | Set ... 
- nio的简单学习
			参考链接: http://www.iteye.com/magazines/132-Java-NIO https://www.cnblogs.com/xiaoxi/p/6576588.html http ... 
- vs2017 乱码
			vs2017默认编码方式并不是UTF-8,似乎是UTF-16,当我们使用中文时,经常会发生乱码. 解决方法:工具->扩展和更新->联机,然后搜索ForceUTF8 我这里已经安装了,没安装 ... 
- synchronized(二)
			package com.bjsxt.base.sync002;/** * 关键字synchronized取得的锁都是对象锁,而不是把一段代码(方法)当做锁, * 所以代码中哪个线程先执行synchro ... 
- ios 汽车品牌展示案例
			汽车组模型 // ZQRGroup.h #import <Foundation/Foundation.h> @interface ZQRGroup : NSObject /** *组标题 ... 
