题意:找出小于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. Solr多核的配置

    Solr 多核(MultiCore)配置 Solr Multicore意义 Solr Multicore 是 solr 1.3 的新特性.其目的一个solr实例,可以有多个搜索应用.< xmln ...

  2. angularjs简单实现$http.post(CORS)跨域及$http.post传参方式模拟jQuery.post

    1.开启angularjs的CORS支持 .config(function($httpProvider) { // CORS post跨域配置 $httpProvider.defaults.useXD ...

  3. Configuration所有配置简介

    // 内存缓存的设置选项 (最大图片宽度,最大图片高度) 默认当前屏幕分辨率                // .memoryCacheExtraOptions(480, 800) // 硬盘缓存的 ...

  4. android scrollview组件禁止滑动的方法

    xml配置:           android:id="@+id/sc_freement"             android:layout_width="fill ...

  5. ScheduledExecutorService定时周期运行指定的任务

    一:简单说明 ScheduleExecutorService接口中有四个重要的方法,当中scheduleAtFixedRate和scheduleWithFixedDelay在实现定时程序时比較方便. ...

  6. BAT染指影视制作 欲全面撬开互联网粉丝经济

    预測: 或靠"用户"模式盈利 除了内容制作,电影发行也在遭遇互联网模式的冲击. 除了给片方支付高额保底以外,随着市场竞争激烈.新进入者都在争夺好片的发行权. 业内预測.再往后,发行 ...

  7. python学习之-成员信息增删改查

    python学习之-成员信息增删改查 主要实现了成员信息的增加,修改,查询,和删除功能,写着玩玩,在写的过程中,遇到的问题,旧新成员信息数据的合并,手机号和邮箱的验证,#!/usr/bin/env p ...

  8. C# WebService 基础实例

    1.整个Demo结构:如下图: 2.新建项目--选择asp.net web服务应用程序TestWebService 3.重新命名Service1.asmx为MyService.asmx 4.右键MyS ...

  9. Mysql查看执行计划

    EXPLAIN(小写explain)显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. EXPLAIN + sql语句可以查看mysql的执行 ...

  10. 认识html文件基本结构

    html文件的结构:一个HTML文件是有自己固定的结构的. <html> <head>...</head> <body>...</body> ...