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) ...
随机推荐
- day05 数据类型
一.整形int 基本使用: 1,用途:记录年龄\等级\各种号码 2定义方式: age=18 age =int(18) x =int(‘123’)#只能将纯数字的字符串转换成整形 print(t ...
- bzoj4310
题解: 后缀数组求出本质不同的串 然后二分答案 贪心判断是否可行 代码: #include<bits/stdc++.h> ; using namespace std; typedef lo ...
- linux:centOs7换源阿里云
备份: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 下载: wget -O /etc/y ...
- python全栈开发笔记---基本数据类型--字符串魔法
字符串: def capitalize(self, *args, **kwargs) test = "aLxs" v = test.capitalize() #capitalize ...
- MATLAB 批量处理图片
function resizephotos(directory, wh, isrecursive, isoverwrite, savetopath, supportFormat) % resizeph ...
- JVM运行时内存区域
JVM运行java程序时会将内存划分为若干个不同的数据区域: (1)程序计数器: 1.占用内存空间不大. 2.程序计数器相当于JVM所执行的字节码(jvm指令)的“行号指示器”,通过程序计数器的“值” ...
- (Java学习笔记) Java Networking (Java 网络)
Java Networking (Java 网络) 1. 网络通信协议 Network Communication Protocols Network Protocol is a set of rul ...
- 201621123001《Java程序设计》第5周学习总结
1.本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 Answer: 本周重要关键词有接口,Comparator接口,Comparable接口,interface关键字,抽象类等. 1 ...
- SharePoint Framework 构建你的第一个web部件(一)
博客地址:http://blog.csdn.net/FoxDave SharePoint客户端web部件是出现在SharePoint页面的控件,但却是在浏览器本地运行的.他们是SharePoint ...
- jquery.datatables设置列隐藏的方法
项目需要根据权限设置表格(使用Juqery.datatables,版本:1.10.16)某列显示或隐藏,百度后有两种实现方法: 1.在columns中设置: columns:[{data:" ...