How many integers can you find

Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7439    Accepted Submission(s): 2200

Problem Description
  Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.
 
Input
  There are a lot of cases. For each case, the first line contains two integers N and M. The follow line contains the M integers, and all of them are different from each other. 0<N<2^31,0<M<=10, and the M integer are non-negative and won’t exceed 20.
 
Output
  For each case, output the number.
 
Sample Input
12 2
2 3
 
Sample Output
7
 
Author
wangye
 
Source
 
题意:给你m个数 可能含有0   问有多少小于n的正数能整除这个m个数中的某一个
题解:特判除零  容斥原理   这m个数 组合时不能直接相乘 应当取最小公倍数
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
ll gcd(ll aa,ll bb)
{
if(bb==)
return aa;
else
return gcd(bb,aa%bb);
}
ll lcm(ll aa,ll bb)
{
return aa*bb/gcd(aa,bb);
}
ll n,m;
ll que[];
ll a[];
ll ggg;
ll coun;
ll slove(ll gg)
{
ll t=,sum=;
a[t++]=-;
for(ll i=;i<coun;i++)
{ ll k=t;
for(ll j=;j<k;j++)
{
a[t++]=que[i]*a[j]*(-);
if(a[t-]>)
a[t-]=lcm(que[i],-a[j]);
else
a[t-]=-lcm(que[i],a[j]);
}
}
for(ll i=;i<t;i++)
sum=sum+(gg/a[i]);
return sum;
}
int main()
{
while(scanf("%I64d %I64d",&n,&m)!=EOF)
{
memset(que,,sizeof(que));
memset(a,,sizeof(a));
coun=;
for(ll i=;i<m;i++)
{
scanf("%I64d",&ggg);
if(ggg!=)
que[coun++]=ggg;
}
printf("%I64d\n",slove(n-));
}
return ;
}
 

HDU 1796 容斥原理的更多相关文章

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

    题目连接   http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理  纪念一下  TMD看了好久才明白DFS... 先贴代码后解释 #includ ...

  2. HDU 1796 (容斥原理)

    容斥原理练习题,忘记处理gcd 和 lcm,wa了几发0.0. #include<iostream> #include<cstdio> #include<cstring& ...

  3. hdu 1796(容斥原理+状态压缩)

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

  4. How many integers can you find HDU - 1796 容斥原理

    题意: 给你一个数n,找出来区间[1,n]内有多少书和n不互质 题解: 容斥原理 这一道题就让我真正了解容斥原理的实体部分 "容斥原理+枚举状态,碰到奇数加上(n-1)/lcm(a,b,c. ...

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

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

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

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

  7. GCD HDU - 1695 容斥原理(复杂度低的版本)

    题意: 让你从区间[a,b]里面找一个数x,在区间[c,d]里面找一个数y.题目上已经设定a=b=1了.问你能找到多少对GCD(x,y)=k.x=5,y=7和y=5,x=7是同一对 题解: 弄了半天才 ...

  8. - Visible Trees HDU - 2841 容斥原理

    题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前 ...

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

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

随机推荐

  1. Giving Data Backup Option in Oracle Forms 6i

    Suppose you want to give the data backup option in Oracle Forms application to some client users, wh ...

  2. 17.KVM安装之虚拟磁盘,安装脚本

    1.创建磁盘 vm.list 指定虚拟磁盘名称和主机名 create_vm.sh    #创建vm.list中的虚拟磁盘,并指定大小100G #!/bin/bash VM_DIR="/opt ...

  3. 使用sublime时报编码错误

    在执行Python脚本时报如下错误: UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-78: ordin ...

  4. Matlab 霍夫变换 ( Hough Transform) 直线检测

    PS:好久没更新,因为期末到了,拼命复习中.复习久了觉得枯燥,玩玩儿霍夫变换直线检测 霍夫变换的基本原理不难,即便是初中生也很容易理解(至少在直线检测上是这样子的). 霍夫变换直线检测的基本原理:(不 ...

  5. 002_kafka_相关术语详细解析

    参考: http://www.cnblogs.com/likehua/p/3999538.html http://kafka.apache.org/documentation.html#getting ...

  6. 网页项目——i家居网站

    本文介绍一个网页项目--i家居网站,小妹初来乍到,欢迎大家评论建议O(∩_∩)O~ 详细源代码.各种框架的实现以及素材均已上传百度云,需要的可以下载: 首页展示 用户注册页面 用户登录页面 商家注册页 ...

  7. (AS3)关于arguments

    一.官方说明 点击访问 二.使用心得 arguments包含了当前执行方法的参数,注意,不包含默认参数! arguments可以全局访问,可以在任何方法里访问,除此之外,在定义变量的时候或者初始化的时 ...

  8. 终于解决了IE8不支持数组的indexOf方法,array的IndexOf方法

    /* 终于解决了IE8不支持数组的indexOf方法 */ if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (el ...

  9. springmvc__SimpleUrlHandlerMapping(对访问地址进行加工,以键值对的形式)

    1.配置web.xml(这里配置url-pattern为/) <!-- 编码过滤器 --> <filter> <filter-name>characterEncod ...

  10. vtune 错误

    The Data Cannot be displayed,there is no viewpoint available for data 1. In a console, run your appl ...