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 ...
随机推荐
- Dottrace 10.0.2 使用心得
开发环境vs2015 软件:JetBrains dotTrace 10.0.2 刚开始不知道怎么下手,多看了一会还有一位仁兄的解释.算是对某个功能小有入门了. 当前会查看某个方法在抓取快照时间它的执行 ...
- js的回调函数详解
本文主要介绍了个人对于javascript中回调函数的理解和使用方法及示例,需要的朋友可以参考下 现在做native App 和Web App是主流,也就是说现在各种基于浏览器的web app框 ...
- Python 字符串(center)
center 描述 Python center() 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串.默认填充字符为空格. 语法 center()方法语法: str.center(w ...
- XHR的对象及用法
function createXHR(){ //检测原生XHR对象是否存在,如果存在刚返回它的新实例: //如果不存在,则检测ActiveX对象; //如果两个都不存 ...
- (转)Ext.onReady详解
(转自)http://hi.baidu.com/kakarot_java/blog/item/8c34e57360472c148601b013.html 我们知道,只有在Ext框架全部加载完后才能在客 ...
- XStream将XML转javaben,出现多余的tag,导致出错
今天在测试银联无卡快捷支付的案例时,多了一个多tag兼容性测试,它是指银联的XML报文中会出现多余的tag,如果我们用XStream解析的时候,没有Javabean的字段可以对应上,就会报错!提示: ...
- Spring Environment(三)生命周期
Spring Environment(三)生命周期 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring Envi ...
- 拼图类APP原型模板分享——简拼
简拼是一款记录美好.抒写情怀的拼图APP,模板设计风格简约文艺,种类齐全. 此原型模板所用到的组件有标签组.水平分隔线.圆形工具.交互动作有结合标签组实现页面跳转,选择组件触发按钮状态变化等. 此原型 ...
- OneZero第三周——预完成功能点统计
本周OneZero将完成“摇一摇”功能. 功能点统计如下: 1.点击主页面“摇一摇”按钮,进入摇一摇界面. 2.摇一摇界面布局(上,中,下). 3.摇动手机,在摇一摇界面中显示一条消费记录. 4.继续 ...
- service层代码相互调用, 导致spring循环依赖,设计上的优化
管理员创建用户需要发送激活邮件, 而发送激活邮件的时候需要判断发件人是不是合法的用户, 因此设计到一个循环依赖的问题 //UserService @Service class UserService{ ...