容斥原理!!

这题首先要去掉=0和>=n的值,然后再使用容斥原理解决

我用的是数组做的……

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#define ll __int64
using namespace std;
int an[],n,m,num,a[];
ll gcd(int a,int b)
{
int t;
if(a<b) swap(a,b);
while(b)
{
t=a;
a=b;
b=t%b;
}
return a;
}
ll lcm(int a,int b)
{
return a/gcd(a,b)*b;
}
ll cal()
{
ll quene[],sum=;
int t=,k,i,j;
quene[t++]=-;
for(i=;i<num;i++)
{
k=t;
for(j=;j<k;j++)
{
if(quene[j]<)
quene[t++]=lcm(-quene[j],an[i]);
else quene[t++]=(-)*lcm(quene[j],an[i]);
}
}
for(i=;i<t;i++)
sum+=(n-)/quene[i];
return sum;
}
int main()
{
int i,j,t,k;
while(cin>>n>>m)
{
num=;k=;
for(i=;i<m;i++)
{
cin>>t;
if(t>&&t<n) an[num++]=t;
}
printf("%I64d\n",cal());
}
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. HDU 1796 How many integers can you find (状态压缩 + 容斥原理)

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

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

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

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

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

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

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

  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 【容斥】

    <题目链接> 题目大意: 给你m个数,其中可能含有0,问有多少小于n的正数能整除这个m个数中的某一个. 解题分析: 容斥水题,直接对这m个数(除0以外)及其组合的倍数在[1,n)中的个数即 ...

随机推荐

  1. Linux 线程 条件变量

    一:条件变量 直接上最基本的两个函数,先抓主要矛盾: //等待条件 int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex ...

  2. 试写Python内建函数range()

    还没查阅源码,先试着练手 class my_range(object): def __init__(self, *args): if not args: raise TypeError, 'range ...

  3. 《Mail电子邮件日志存储的管理》RedHat6.3——以一举三

    我们都知道很多日志的模块都是放在这下面的 要是想修改或是添加其他服务的日志,怎么办?修改下面的配置文件 测试下是否ok 轮转日志和定位分析和分析日志汇总报告: 安装logwatch软件包,这个没啥说的 ...

  4. c#枚举自定义,用于数据绑定。

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Enum)] public ...

  5. Spring-Mybatis 异常记录(1)

    Spring  applicationconfig.xml如下 <?xml version="1.0" encoding="UTF-8"?> < ...

  6. 例题6-4 Broken Keyboard UVa11988

    题目分析: 起初这道题目没有做出来,原因是我一直想把整块区域一并插入,而不是逐个插入.今后做题应该注意这个问题,把问题分解去考虑,也许会少走许多弯路. 下边附上AC代码 #include <cs ...

  7. SATA SAS SSD 硬盘介绍和评测

    SATA SATA的全称是Serial Advanced Technology Attachment,是由Intel.IBM.Dell.APT.Maxtor和Seagate公司共同提出的硬盘接口规范. ...

  8. python: 生成guid

    其实经常需要生成一个guid,在各种场合使用...也简单写个小脚本实现吧. 实现下来发现速度比较慢... import uuid import sys def show_ver(): print 'g ...

  9. Repeat Header / Keep Header Visible in Tables in RS 2008

    You selected "Repeat header rows on each page" or "Keep header rows visible while scr ...

  10. jQuery实现分页

    转载地址 http://www.cnblogs.com/xiaoruoen/archive/2012/01/11/2318199.html ;( function($){ $.extend({ &qu ...