hdu How many integers can you find
题意:找出小于n是m个数每个数的倍数的数的个数。
思路:用二进制表示是那几个数的倍数。 二进制进行容斥,去掉小于0的数。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; __int64 n,m,g;
__int64 a[],b[]; __int64 gcd(__int64 a,__int64 b)
{
return b==?a:gcd(b,a%b);
} int main()
{
while(scanf("%I64d%I64d",&n,&m)!=EOF)
{
memset(a,,sizeof(a));
__int64 cnt=;
for(int i=; i<m; i++)
{
__int64 x;
scanf("%I64d",&x);
if(x)
a[cnt++]=x;
}
__int64 ans=;
for(int i=; i<(<<cnt); i++)
{
__int64 xx=;
__int64 x=;
memset(b,,sizeof(b));
for(int j=; j<cnt; j++)
{
if(i&(<<j))
{
b[xx]=a[j];
xx++;
x*=a[j];
}
}
if(xx>)
{
g=(b[]*b[])/gcd(b[],b[]);
for(int k=; k<xx; k++)
{
g=(g*b[k])/gcd(g,b[k]);
}
x=g;
}
if(xx%!=)
{
ans+=((n-)/x);
}
else
{
ans-=((n-)/x);
}
}
printf("%I64d\n",ans);
}
return ;
}
hdu How many integers can you find的更多相关文章
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- HDU How many integers can you find 容斥
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796How many integers can you find(简单容斥定理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 Howmany integers can you find (容斥原理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 How many integers can you find(容斥原理)
题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description ...
- HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...
- HDU 1796 How many integers can you find 容斥入门
How many integers can you find Problem Description Now you get a number N, and a M-integers set, y ...
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- python列表操作总结
list是python中非常重要的类型/数据结构,总结如下: 符号说明 l:列表 l2:新列表 e:元素 index:位置 方法: 原地修改: l.append(e) l.insert(index, ...
- 【Java】Java8新增的Lambda表达式_学习笔记
一.Lambda表达式可以简化创建匿名内部类对象 1.不需要new XXX(){}这种繁琐代码. 2.不需要指出重写的方法名. 3.不要给出重写的方法的返回值类型. 4.Lambda相当于一个匿名方法 ...
- 常用的Linux操作一
Linux 常用的操作必须明白. 1.ls 和ll 列出文件的目录. 2.tail -f XXX 查看文件. 3.chmod -R 777 XXX.jar 赋予权限 4.cat 查看文件 -n 对 ...
- Android Scroller类的详细分析
尊重原创作者,转载请注明出处: http://blog.csdn.net/gemmem/article/details/7321910 Scroller这个类理解起来有一定的困难,刚开始接触Scrol ...
- [PWA] 10. Trigger a version update
When the refersh button is clicked, we need to tell the waiting service worker to replace the curren ...
- iTunes 11.2更新下载:改善播客阅读
昨日,苹果公布了iTunes 11.2更新,新版别改善了播客阅读的方法,让用户能够在新的"未播映的"标签中疾速找到没有赏识的单集,其他功用包括主动删去现已播映的单集,并可在&quo ...
- rabbitmq Clustering Guide--官方
官方文档地址:http://www.rabbitmq.com/documentation.html A RabbitMQ broker is a logical grouping of one or ...
- navicat导入mysql数据库sql时报错或数据不完全问题
错误详情:[Err] [Imp] 2006 - MySQL server has gone away 或无提示错误,但是导入数据明显缺少字段和数据 找到服务器上的MYSQL安装目录下的my.ini文件 ...
- Android(java)学习笔记231:服务(service)之混合方式开启服务
1. 前面我们已经讲过可以使用两种方式开启服务 startService----stopService: oncreate() ---> onstartCommand() ---& ...
- 如何参与一个GitHub开源项目
Github作为开源项目的著名托管地,可谓无人不知,越来越多的个人和公司纷纷加入到Github的大家族里来,为开源尽一份绵薄之力.对于个人来讲,你把自己的项目托管到Github上并不表示你参与了Git ...