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) ...
随机推荐
- outline: none;
outline: none:用在去掉某个选中后显示的外边框,(追求细节) http://www.w3school.com.cn/cssref/pr_outline.asp
- 每天CSS学习之box-shadow
box-shadow是CSS3的属性,目的是给盒子添加一个或多个阴影.怎么感觉有点像光明使者使用该法术照亮敌人的阴暗面? box-shadow一共有六个属性,请看: box-shadow: h-sha ...
- java有关构造器的面试题详解
1,编译器只会提供自动提供一个默认的无参数的构造函数 2,如果程序员没有给类A没有提供构造函数,则编译器会自动提供一个默认的无参数的构造函数,如果用户提供了自己的构造函数,则编译器就不在提供默认的无参 ...
- [Leetcode 881]船救人 Boats to Save People 贪心
[题目] The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each b ...
- mysql存储过程造数
性能测试时,数据库表通常需要很多数据,此时我们可以用存储过程来造数,以下代码mysql.Oracle都可以用 首先,先查看数据库表的设计,可以看到每张表有多少字段,分别都是什么类型,哪个字段是自动增长 ...
- 用MyEclipse开发REST Web Service
MyEclipse 在线订购年终抄底促销!火爆开抢>> MyEclipse最新版下载 使用MyEclipse开发RESTWeb服务来放大您的Web应用程序.在本教程示例中,您将创建一个简单 ...
- <Google><APAC><kickstart><2017.05.07><2017RoundB>
Google APAC kickstart 网址链接 我的所有solution代码和文件请点击 前言 这个比赛的题怎一个变态了得,虽然是第一次参赛,抱着熟悉流程的心态去的,但仍然被虐得一颤一颤的╮(╯ ...
- 高级数据类型--列表[list]
List(列表) 是 Python 中使用 最频繁 的数据类型,在其他语言中通常叫做 数组,专门用于存储 一串 信息,列表用 [] 定义,数据 之间使用 , 分隔,列表的 索引 从 0 开始. nam ...
- L256 阅读理解
1主旨题 2细节题 题干关键词 人名,地名,专有名词,时间,和主题相关的核心词汇,带特殊标点的词汇 干扰项 词意猜测
- elasticsearch学习笔记——相关插件和使用场景
logstash-input-jdbc学习 ES(elasticsearch缩写)的一大优点就是开源,插件众多.所以扩展起来非常的方便,这也造成了它的生态系统越来越强大.这种开源分享的思想真是与天朝格 ...