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. Redis启动出错 noauth authentication required.

    输入认证过的密码即可. 在命令行中运行: auth password

  2. Asp.Net使用Yahoo.Yui.Compressor.dll压缩Js|Css

    网上压缩css和js工具很多,但在我们的系统中总有特殊的地方.也许你会觉得用第三方的压缩工具很麻烦.我就遇到了这样问题,我不想在本地压缩,只想更新到服务器上去压缩,服务器压缩也不用备份之类的操作.于是 ...

  3. Spring Cloud-Bus(十二)

    说明 用于分布式上所有微服务都连接到消息总线上面.进行统一的通知 Config动态刷新 configClient configClient通过/actuator/bus-refresh端点通知消息总线 ...

  4. FADE:云存储中数据安全删除

         FADE: Secure Overlay Cloud Storage with File Assured Deletion ,论文发表于SecureComm,C类.      香港大学的研究 ...

  5. 洛谷 P1768 天路

    P1768 天路 题目描述 “那是一条神奇的天路诶~,把第一个神犇送上天堂~”,XDM先生唱着这首“亲切”的歌曲,一道猥琐题目的灵感在脑中出现了. 和C_SUNSHINE大神商量后,这道猥琐的题目终于 ...

  6. Java EE: XML Schemas for Java EE Deployment Descriptors(Java Web的web.xml头web-app标签上的XML模式)

    继上几篇文章 http://www.cnblogs.com/EasonJim/p/6221952.html http://www.cnblogs.com/EasonJim/p/6959120.html ...

  7. Java中的事务

    Java中的事务 学习了:https://www.cnblogs.com/chengpeng15/p/5802930.html 膜拜一下 org 分为三类:jdbc事务.jta事务.容器事务:

  8. PL/SQL Developer自己主动补全SQL语句

    快捷输入SQL语句,比如输入s,按下空格,自己主动替换成SELECT;再比如,输入se,按下空格, 自己主动替换成SELECT * FROM,很方便,节省了大量的时间去编写反复的SQL语句. 设置方法 ...

  9. JAVA进阶-泛型

    >泛型:泛型指代了參数的类型化类型,一般被用在接口.类.方法中 >作用:用来确定參数的范围,在书写代码的时候提前检查代码的错误性 >泛型的声明,下面给出类声明,依此类推: class ...

  10. Mysql 索引需要了解的几个注意

    索引是做什么的? 索引用于快速找出在某个列中有一特定值的行.不使用索引,MySQL必须从第1条记录开始然后读完整个表直到找出相关的行.表越大,花费的时间越多.如果表中查询的列有一个索引,MySQL能快 ...