题目链接

题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算。

思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 } + sum{ 整除三个的数 }………………所以是奇加偶减,而整除 k 个数的数可以表示成 lcm(A1,A2,…,Ak) 的倍数的形式。所以算出最小公倍数,

//HDU 1796
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std ; LL sh[] ; LL gcd(LL a,LL b)
{
return b == ? a : gcd(b,a%b) ;
}
int main()
{
LL a,b ;
while(~scanf("%I64d %I64d",&a,&b))
{
int c ,j = ;
for(int i = ; i < b ; i++)
{
scanf("%d",&c) ;
if(c > && c < a)
sh[j++] = c ;
}
b = j;
// sort(sh,sh+b);
LL ans = ;
for(int i = ; i < ( << b) ; i++)//(1 << b)-1种情况
{
LL num = ,lcm = ;
for(int j = ; j < b ; j++)
{
if(i & ( << j))
{
num ++ ;
lcm = lcm*sh[j]/gcd(lcm,sh[j]) ;
}
}
if(num & )
ans += (a-)/lcm ;
else
ans -= (a-)/lcm ;
}
printf("%I64d\n",ans) ;
}
return ;
}

HDU 1796 How many integers can you find (状态压缩 + 容斥原理)的更多相关文章

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

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

  2. ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

    HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & ...

  3. HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  4. hdu 4114 Disney's FastPass(最短路+状态压缩)

    Disney's FastPass Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  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 容斥入门

    How many integers can you find Problem Description   Now you get a number N, and a M-integers set, y ...

  7. hdu 1796 How many integers can you find 容斥定理

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

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

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

  9. HDU 1796 How many integers can you find(容斥原理+二进制/DFS)

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

随机推荐

  1. Linux系统木马后门查杀方法详解

    木马和后门的查杀是系统管理员一项长期需要坚持的工作,切不可掉以轻心.以下从几个方面在说明Linux系统环境安排配置防范和木马后门查杀的方法: 一.Web Server(以Nginx为例) 1.为防止跨 ...

  2. C# 执行Cmd窗口中的命令 [复制文件实例]

    /// <summary> /// 复制文件夹 /// </summary> /// <param name="sCmd"></param ...

  3. C语言函数返回数组

    #include "stdio.h"/*int* set(int a,int *c){ int *b; b=malloc(sizeof(int)*3); c[0]=a; c[1]= ...

  4. 项目进阶 之 集群环境搭建(三)多管理节点MySQL集群

    上次的博文项目进阶 之 集群环境搭建(二)MySQL集群中,我们搭建了一个基础的MySQL集群,这篇博客咱们继续讲解MySQL集群的相关内容,同时针对上一篇遗留的问题提出一个解决方案. 1.单管理节点 ...

  5. PB打开ole控件IE浏览器版本问题_指定Webbrowser控件所用IE内核版本(转)

    如果电脑上安装了IE8或者之后版本的IE浏览器,Webbrowser控件会使用IE7兼容模式来显示网页内容.解决方法是在注册表中为你的进程指定引用IE的版本号. 比如我的程序叫做a.exe 对于32位 ...

  6. < java.util >-- Collection接口

    Collection:    |--List:有序(元素存入集合的顺序和取出的顺序一致),元素都有索引.元素可以重复.    |--Set:无序(存入和取出顺序有可能不一致),不可以存储重复元素.必须 ...

  7. panel面板

    描述:作为承载其他内容的容器的,装载其他组件基础,可折叠.关闭.最大化.最小化和自定义行为.面板可以很容易地嵌入到web页面的任何位置. 其他属性请参考api! 案例1:纯html生成 <div ...

  8. 深入分析windows下配置wamp环境各模块的版本兼容性

    版本相关概念说明: ts/nts: thread safety 线程安全 TS refers to multithread capable builds. NTS refers to single t ...

  9. ionic 运行过程中动态切换API服务器地址

    ionic 运行过程中动态切换API服务器地址 keywords: ionic,phonegap,cordova,网络制式,动态切换,变更,API,服务器地址,$resource,localstora ...

  10. dancing link

    http://www.cnblogs.com/grenet/p/3145800.html 链接给的博客写的很好,比较好懂. 可惜不是c语言... 于是决定自己要建一个模板. 一道裸题:hustoj 1 ...