hdu1796 How many integers can you find
//设置m,Q小于n可以设置如何几号m随机多项整除
//利用已知的容斥原理
//ans = 数是由数的数目整除 - 数为整除的两个数的数的最小公倍数 + 由三个数字。。。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 110 ;
typedef __int64 ll ;
int a[maxn] ;
int len ;
int n , m ;
ll gcd(ll a , ll b)
{
if(b == 0)
return a ;
return gcd(b, a%b) ;
}
int dfs(int pos , ll lcm)
{
int ans = 0 ;
for(int i = pos ;i <= len;i++)
{
ll lcm_n = lcm*a[i]/gcd(lcm , a[i]) ;//最小公倍数可能会爆int,被坑了一下
ans += (n-1)/lcm_n - dfs(i+1 , lcm_n) ;
}
return ans ;
}
int main()
{
while(~scanf("%d%d" , &n , &m))
{
len = 0 ;
for(int i = 1;i <= m;i++)
{
int t ;
scanf("%d" , &t) ;
if(!t) continue ;//可能会有0
a[++len] = t ;
}
int ans = dfs(1 , 1) ;
printf("%d\n" , ans) ;
}
return 0 ;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
hdu1796 How many integers can you find的更多相关文章
- 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 ...
- 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 ...
- HDU1796 How many integers can you find(容斥原理)
题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ...
- 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 ...
- How many integers can you find(hdu1796)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- [LeetCode] Sum of Two Integers 两数之和
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- [LeetCode] Divide Two Integers 两数相除
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- hdu4734(数位dp)
hdu4734 给定 a和b, 问区间[0,b]内有多少个数字的f(i) <=f(a) dp[i][s] 表示i位的数字的f<=s 所以比如如果第i+1位选择数字5之后, 那么只要剩下的i ...
- css3仿山猫侧边栏
演示:http://jsfiddle.net/Adce2/ 其主要思想: 1, 先画边栏html. 2, 使用css3分别财产close sidebar-content动图片. 3, 使用css3的k ...
- VMware vSphere 服务器虚拟化之十七 桌面虚拟化之安装View链接服务器
VMware vSphere 服务器虚拟化之十七 桌面虚拟化之安装View链接服务器 View链接服务器(View Connection Server)是Vmware Horizon View桌面虚拟 ...
- POJ 3684 Priest John's Busiest Day 2-SAT+输出路径
强连通算法推断是否满足2-sat,然后反向建图,拓扑排序+染色. 一种选择是从 起点開始,还有一种是终点-持续时间那个点 開始. 若2个婚礼的某2种时间线段相交,则有矛盾,建边. easy出错的地方就 ...
- 破解win2008r2服务器域用户名
启动PE系统 进入 cmd窗口 cd 进入 win2008r2服务器的安装盘(假设为d:) d: cd windows/system32 ren osk.exe osk02.exe #重命令屏幕键盘 ...
- hdu 5092 Seam Carving
这道题 我没看出来 他只可以往下走,我看到的 8-connected :所以今天写一下如果是 8-connected 怎么解: 其实说白了这个就是从上到下走一条线到达最后一行的距离最小: 从Map[a ...
- emeditor 配置教程
1.众多的图形界面配置功能 通过查看EmEditor的安装目录,可以发现,EmEditor有几个配置文件,理论上应该可以通过修改配置文件来达到配置EmEditor的目 的.然而,打开配置文件一看,如果 ...
- Windows Phone 8.1 新功能 - 应用栏控件
2014年4月3日的微软Build 2014 大会上.Windows Phone 8.1 正式公布. 相较于Windows Phone 8.不论从用户还是开发人员的角度,都产生了非常大的变化. 接下来 ...
- [ Talk is Cheap Show me the CODE ] : jQuery Mobile工具栏
[ Talk is Cheap Show me the CODE ] : jQuery Mobile工具栏 Written In The Font " Wirte less Do more& ...
- CSS设计指南之浮动与清除
原文:CSS设计指南之浮动与清除 浮动意思就是把元素从常规文档流中拿出来,浮动元素脱离了常规文档流之后,原来紧跟在其后的元素就会在空间允许的情况下,向上提升到与浮动元素平起平坐. 一.浮动 CSS设计 ...