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 ...
随机推荐
- Java.Annotations
Annotation 0. Annotation Tricks http://developer.android.com/reference/java/lang/annotation/Annotati ...
- javascript 高级程序设计 五
1.变量: ECMAScript中的基本类型都是值类型Boolean,Number,Null,Undefined和String,在这里JS和其他的语言有所不同,就是JS中的String是值类型 而不像 ...
- Netty 源码(二)NioEventLoop 之 Channel 注册
Netty 源码(二)NioEventLoop 之 Channel 注册 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一 ...
- 第一个spring boot 程序
安装.运行.预览省略 错误1:8080端口被IIS占用,关闭它 Description: The Tomcat connector configured to listen on port 8080 ...
- g2o相关问题cs.h,以及no matching function for call to ‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(Block*&)
1.对于cs.h找不到的情况 1)编译的时候一定要把csparse在EXTERNAL文件中,编译进去. 2)修改CMakeLists.txt文件中的include_directories中的${CPA ...
- Homebrew -- mac 缺失包补充工具
https://brew.sh/index_zh-cn.htmlhttps://brew.sh/ 非root权限下运行 # github 源代码 https://github.com/Homebrew ...
- PSP(3.30——4.5)以及周记录
1.PSP 3.30 12:00 13:00 10 50 Account前端 A Y min 13:00 13:20 0 20 站立会议 A Y min 15:15 17:00 20 85 Accou ...
- NYOJ 1016 判断两线段是否相交
#include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #inc ...
- 2019.01.20 bzoj2388: 旅行规划(分块+凸包)
传送门 分块好题. 题意:维护区间加,维护区间前缀和的最大值(前缀和指从1开始的). 思路: 考虑分块维护答案. 我们把每个点看成(i,sumi)(i,sum_i)(i,sumi)答案一定会在凸包上 ...
- 2019.01.19 bzoj4592: [Shoi2015]脑洞治疗仪(ODT)
传送门 ODT水题. 支持区间01赋值,区间填补(把区间[l,r][l,r][l,r]从左往右数kkk个1都变成0),区间查询最长连续1个数. 思路: 区间填补操作感觉不是很好弄,写线段树的神仙可以套 ...