题目链接

题意 : 给你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. Zygote(app_process)相关分析2

    在前一篇文章中已经分析了从init.c到Zygote(app_process)的启动流程. 今天开始分析frameworks/base/cmds/app_process/app_main.cpp. s ...

  2. DataReader 链接关闭解惑篇

    不管是啥xxDataReader,都是继承DataReader实现的,所以是有共性的,因此标题就以DataReader为题了. 情况一:DataReader 默认链接不关闭 static void M ...

  3. Go时间戳和日期字符串的相互转换

    Go语言中,获取时间戳用time.Now().Unix(),格式化时间用t.Format,解析时间用time.Parse. 看实例代码: package main import ( "fmt ...

  4. centos rsync安装配置

    安装 1 yum -y install rsync ---------------------服务器安装------------------------------- 创建基础配置文件 1 2 3 4 ...

  5. Apple Watch应用开发经验谈:我遇到的那些坑

    本文作者张忠良是滴答清单Apple Watch版应用的开发工程师,他用了一周的时间使用纯Objective-C语言完成了Apple Watch版滴答清单应用的开发工作.在这里,他从开发角度阐述了个人对 ...

  6. IOS内存管理「3」- 自动释放的基本概念和用法

  7. (转)android Fragments详解三:实现Fragment的界面

    为fragment添加用户界面 fragment一般作为activity的用户界面的一部分,把它自己的layout嵌入到activity的layout中.    一个 要为fragment提供layo ...

  8. 关于SVN 目录结构,使用教程

    SVN使用教程:http://www.cnblogs.com/armyfai/p/3985660.html Subversion有一个很标准的目录结构,是这样的.比如项目是proj,svn地址为svn ...

  9. Datawarehouse

  10. 为SM30视图分配事务代码

    Tcode:SE93