Code:

#include<cstdio>
using namespace std;
typedef long long ll;
const int R=13;
ll a[R];
ll n,ans;
int m,cnt=0;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void dfs(int cur,ll lcm,int id){
if(cur>cnt)return;
lcm=a[cur]/gcd(a[cur],lcm)*lcm; if(id)ans+=(n-1)/lcm;
else ans-=(n-1)/lcm;
for(int i=cur+1;i<=cnt;++i)
dfs(i,lcm,!id);
}
int main(){
while(scanf("%lld%d",&n,&m)!=EOF)
{
ans=cnt=0;
for(int i=1;i<=m;++i){
ll k;
scanf("%lld",&k);
if(k)a[++cnt]=k;
}
for(int i=1;i<=cnt;++i)
dfs(i,a[i],1);
printf("%lld\n",ans);
}
return 0;
}

  

How many integers can you find HDU - 1796_容斥计数的更多相关文章

  1. Co-prime HDU - 4135_容斥计数

    Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...

  2. HDU 4135 容斥

    问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...

  3. HDU 2841 容斥 或 反演

    $n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...

  4. HDU 1695 容斥

    又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...

  5. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  6. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  7. 题解报告:hdu 4135 Co-prime(容斥定理入门)

    Problem Description Given a number N, you are asked to count the number of integers between A and B ...

  8. HDU 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 1796How many integers can you find(简单容斥定理)

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

随机推荐

  1. Bootstrap 表单控件状态(验证状态)

    在制作表单时,不免要做表单验证.同样也需要提供验证状态样式,在Bootstrap框架中同样提供这几种效果.1..has-warning:警告状态(黄色)2..has-error:错误状态(红色)3.. ...

  2. 一种脱离VC编程软件的方法学习C/C++编程(搭建EditPlus实现在文本编辑框中执行.c文件

    网上下载一个EditPlus记事本安装好后就可以按照下面步骤进行搭建环境了: 一.工具(Tools)→配置用户工具(Configure UserTools...),[添加工具](Add Tool> ...

  3. windows 2003一个网卡绑定多个IP地址

    1.打开“网络连接”,选中需要添加多个IP的“本地连接”-->右键-->“属性”: 2.从“常规”中找到“Internet 协议(TCP/IP)属性”: 3.选择手动设置IP地址.网关.掩 ...

  4. Java循环遍历中直接修改遍历对象

    Java 循环遍历中直接修改遍历对象如下,会报异常: for (ShopBaseInfo sp: sourceList) { if(sp.getId()==5){ sourceList.remove( ...

  5. xtrabackup增量备份mysql +MHA

    http://blog.csdn.net/yanggd1987/article/category/2214421 https://www.centos.bz/2013/09/innobackupex- ...

  6. ZOJ 3209

    精确覆盖 #include <iostream> #include <cstdio> #include <cstring> #include <algorit ...

  7. POJ3126——Prime Path

    非常水的一道广搜题(专业刷水题). .. #include<iostream> #include<cstdio> #include<queue> #include& ...

  8. JS禁用微信复制链接、禁用转发

    $(function () { function onBridgeReady() { WeixinJSBridge.call('hideOptionMenu'); } if (typeof Weixi ...

  9. Fitnesse Slim的使用

    官网上的使用说明:http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.Slim 本文主要介绍Slim常用的几种表格,更多 ...

  10. 《游戏脚本的设计与开发》-(RPG部分)3.8 通过脚本来自由控制游戏(一)

    注意:本系列教程为长篇连载无底洞.半路杀进来的朋友,假设看不懂的话.请从第一章開始看起.文章文件夹请点击以下链接. http://blog.csdn.net/lufy_legend/article/d ...