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 ...
随机推荐
- git回退文件修改
假设git仓库某个文件的提交信息如下: [cxy@localhost-live mate-power-manager]$ git log -n3 SPECS/mate-power-manager.sp ...
- linux系统中的进程状态分析
转载地址:https://blog.csdn.net/shenwansangz/article/details/51981459 linux是一个多用户,多任务的系统,可以同时运行多个用户的多个程序, ...
- python: "TypeError: 'type' object is not subscriptable"
目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a di ...
- 拼图类APP原型模板分享——简拼
简拼是一款记录美好.抒写情怀的拼图APP,模板设计风格简约文艺,种类齐全. 此原型模板所用到的组件有标签组.水平分隔线.圆形工具.交互动作有结合标签组实现页面跳转,选择组件触发按钮状态变化等. 此原型 ...
- Max Chunks To Make Sorted II LT768
This question is the same as "Max Chunks to Make Sorted" except the integers of the given ...
- 微信小程序播放视频发送弹幕效果
首先.先来看一下效果图 然后.再看一下官方文档API对video的说明 相关属性解析: danmu-list:弹幕列表 enable-danmu:是否显示弹幕 danmu-btn:弹幕按钮 contr ...
- linux 虚拟机设置
1.可以用网桥方式 2.可以用一个回环虚拟网卡即可.
- JSON数据映射之元素可见控制
1.效果: 2.demo 源码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- 阿里云help
docker 技术的安全性问题,如果一个集群多个用户不希望互相可以看到对方的docker镜像和容器,怎么办? .... http://mirrors.aliyun.com/help/centos yu ...
- C# 使用 HttpPost 请求调用 WebService
之前调用 WebService 都是直接添加服务引用,然后调用 WebService 方法的,最近发现还可以使用 Http 请求调用 WebService.这里还想说一句,还是 web api 的调用 ...