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 (Java/Other)
Total Submission(s) : 95 Accepted Submission(s) : 30
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.
Input
Output
Sample Input
12 2
2 3
Sample Output
7
Author
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff;
LL a[100]; struct node
{
LL num;
int cnt;
}ans[100005]; int tot,m;
LL n;
LL gcd(LL a,LL b)
{
return b==0?a:gcd(b,a%b);
} void dfs(int pos,LL lcm,int cnt)
{
if(pos>=m)
{
if(cnt==0)
return;
ans[tot].num=(n-1)/lcm;
ans[tot++].cnt=cnt;
return;
}
if(a[pos]==0)
dfs(pos+1,lcm,cnt);
else
{
dfs(pos+1,lcm*a[pos]/gcd(lcm,a[pos]),cnt+1);
dfs(pos+1,lcm,cnt);
} } int main()
{
while(~scanf("%lld%d",&n,&m))
{
for(int i=0; i<m; i++)
{
scanf("%lld",&a[i]); } tot=0;
dfs(0,1,0);
LL ass=0;
for(int i=0; i<tot; i++)
{
if(ans[i].cnt%2)
ass+=ans[i].num;
else
ass-=ans[i].num;
}
printf("%lld\n",ass);
}
return 0;
}
Hdu1796 How many integers can you find 2017-06-27 15:54 25人阅读 评论(0) 收藏的更多相关文章
- hdu 1231, dp ,maximum consecutive sum of integers, find the boundaries, possibly all negative, C++ 分类: hdoj 2015-07-12 03:24 87人阅读 评论(0) 收藏
the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is o ...
- Work 1(导游类)(2017.06.27)
- 2017年最新15个漂亮的 HTML 摄影网站模板
摄影是一门艺术,它需要大量的耐心和努力工作来捕捉那些精彩的瞬间.如果你是一位热情的摄影师,想要建立一个网站来展示那些高质量的摄影作品,那么你找对地方了.本文包含15个最佳的摄影网站模板,你可以使用这些 ...
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.27
2017.04.27 天气阴沉 小雨. 时间:上午 9:35 ---10:10分 地点:陆大314实验室 会议内容:每天充分利用好大课间的时间,今天对昨天的的细节问题进行了讨论及方法更正.时间不等人这 ...
- Visual Studio 2017 Enterprise (15.3)
版本15.3更新在用户离线下载时更加人性化,包含了进度显示,下载出错可以输入R,进行下载的重新尝试,并在当前下载框下继续下载为完成的作业,结合 --layout 参数的离线文件的检查和修复,并且在下载 ...
- Visual Studio 2017 Enterprise 发布 15.3.3 版,附离线安装包百度网盘下载。
Visual Studio 2017 Enterprise 发布 15.3.3 版,附离线安装包百度网盘下载. Visual Studio 2017 Enterprise 更新至 15.3.3 ,本安 ...
- 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(容斥原理)
题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ...
- hdu1796 How many integers can you find
//设置m,Q小于n可以设置如何几号m随机多项整除 //利用已知的容斥原理 //ans = 数是由数的数目整除 - 数为整除的两个数的数的最小公倍数 + 由三个数字... #include<cs ...
随机推荐
- Eclipse中的maven项目搭建
一.eclipse中的maven设置 1.打开“首选项”----> "maven"---->"Installations".用来查看maven的使用 ...
- iOS.WWDC
1. ASCIIwwdc: Searchable full-text transcripts of WWDC sessions http://asciiwwdc.com
- idea 高级调试技巧
两年前写过一篇关于idea的高级用法,今天再来一篇关于调试方面的技巧讲解: 一.条件断点 循环中经常用到这个技巧,比如:遍历1个大List的过程中,想让断点停在某个特定值. 参考上图,在断点的位置,右 ...
- FoxMail提示:请求的名称有效,但是找不到请求的类型的数据
FoxMail发送或者接收邮件的时候,提示如下信息: <错误信息:请求的名称有效,但是找不到请求的类型的数据> 一,DNS解析不稳定 解决办法:修改本地电脑上面本地连接中的DNS地址< ...
- UVA-1364.Knights of the Round Table 无向图BCC
题目链接:https://vjudge.net/problem/UVA-1364 题意:有n个人参加会议,互相憎恨的人不能坐在相邻的位置,并且每个会议参加的人数必须是奇数,求有多少个人不能参加任何一个 ...
- boost timer代码学习笔记
socket连接中需要判断超时 所以这几天看了看boost中计时器的文档和示例 一共有五个例子 从简单的同步等待到异步调用超时处理 先看第一个例子 // timer1.cpp: 定义控制台应用程序的入 ...
- h5解决移动端上滑卡顿问题
select{ -webkit-overflow-scrolling: touch;/*解决移动端滑动卡顿问题*/ -webkit-transform: translateZ(0px);/*开启GPU ...
- centos配置备忘(apache\php\mysql)
1. 安装apache\php\mysql=======================================yum -y install httpd php mysql mysql-ser ...
- Epson Pos Printer for .net
注:因发现各网站爬虫随意收集文章,故做此声明:版权归原作者(Leaf.Duan)所有,转载还请著名出处,谢谢 设备信息 Epson TM-T88IV Thermal Printer,爱普生 TM-T8 ...
- 矩阵快速幂小结-Hdu2604
矩阵快速幂可以想象为线性代数的矩阵相乘,主要是运用于高效的计算矩阵高次方. 将矩阵两两分组,若要求a^n,即知道a^(n/2)次方即可,矩阵快速幂便是运用的这个思路. 比方想求(A)^7那么(A)^6 ...