题意:找出小于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的更多相关文章

  1. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  2. HDU How many integers can you find 容斥

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. HDU 1796How many integers can you find(简单容斥定理)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  4. HDU 1796 Howmany integers can you find (容斥原理)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. HDU 1796 How many integers can you find(容斥原理)

    题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description    ...

  6. HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)

    HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...

  7. 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 ...

  8. HDU 1796 How many integers can you find (状态压缩 + 容斥原理)

    题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...

  9. A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. 从Delphi 7升级到Delphi XE

    Delphi 7和XE中间有好几个版本号,可都不太流行,一是由于Delphi有些边缘化,二是7在XP环境下是近乎完美的版本号.市场上关于delphi的书越来越少,提供从7升级到XE介绍的资料差点儿没用 ...

  2. Toast的使用具体解释

    Android中提供一种简单的Toast消息提示框机制,能够在用户点击了某些button后,提示用户一些信息,提示的信息不能被用户点击,Toast的提示信息依据用户设置的显示时间后自己主动消失.Toa ...

  3. migrate from weblogic to tomcat: directory mapping--reference

    Question: I am trying to migrate from weblogic to tomcat. in weblogic I have <virtual-directory-m ...

  4. [转] java中的匿名内部类总结

    匿名内部类也就是没有名字的内部类 正因为没有名字,所以匿名内部类只能使用一次,它通常用来简化代码编写 但使用匿名内部类还有个前提条件:必须继承一个父类或实现一个接口 实例1:不使用匿名内部类来实现抽象 ...

  5. 通过GitHub Pages建立个人站点(详细步骤)

    1 Git简介 2 为什么使用Github Pages 3 创建Github Pages 3.1 安装git工具. 3.2 两种pages模式 3.3 创建步骤 3.4 常用命令 4 使用Jekyll ...

  6. Camera2Raw

    This sample demonstrates how to use the Camera2 API to capture RAW camera buffers and save them as D ...

  7. Android(java)学习笔记214:开源框架的文件上传(只能使用Post)

    1.文件上传给服务器,服务器端必然要写代码进行支持,如下: 我们新建一个FileUpload.jsp的动态网页,同时我们上传文件只能使用post方式(不可能将上传数据拼凑在url路径下),上传数据Ap ...

  8. CDOJ 92 – Journey 【LCA】

    [题意]给出一棵树,有n个点(2≤N≤105),每条边有权值,现在打算新修一条路径,给出新路径u的起点v,终点和权值,下面给出Q(1≤Q≤105)个询问(a,b)问如果都按照最短路径走,从a到b节省了 ...

  9. 数据库 ORM框架 ORMLite

    几个ORM框架的比较 先介绍一下ORM的概念,以前也一直听说,不过没详细了解啥意思.其全称叫做对象关系映射(Object Relation Mapping),是一种程序设计技术,用于实现面向对象编程语 ...

  10. 在ASP.NET将程序中将上传的附件存储到另一台文件服务器上的实现

    假定有两台服务器:A和B,其中A为Web服务器(IP:192.123.1.1, 为iis发布程序的服务器 ),B为文件服务器(IP: 192.123.2.2) 在文件服务器B中某个磁盘下创建一个共享文 ...