思路:二进制解决容斥问题,就和昨天做的差不多。但是这里题目给的因子不是质因子,所以我们求多个因子相乘时要算最小公倍数。题目所给的因数为非负数,故可能有0,如果因子为0就要删除。

代码:

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = + ;
const int seed = ;
const int MOD = ;
const int INF = 0x3f3f3f3f;
ll a[];
ll n, m;
ll gcd(ll aa, ll b){
return b == ? aa : gcd(b, aa % b);
}
ll solve(){
ll ans = ;
for(ll i = ; i < ( << m); i++){
int num = ;
ll val = ;
for(int j = ; j < m; j++){
if(i & ( << j)){
val = val / gcd(val, a[j]) * a[j];
num++;
}
}
if(num & ){
ans += n / val;
}
else{
ans -= n / val;
}
}
return ans;
}
int main(){
while(~scanf("%lld%lld", &n, &m)){
n--;
for(int i = ; i < m; i++){
scanf("%lld", &a[i]);
if(a[i] == ){
i--;
m--;
}
}
printf("%lld\n", solve());
}
return ;
}

HDU 1796 How many integers can you find(容斥)题解的更多相关文章

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

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

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

  4. HDU 1796 How many integers can you find (容斥)

    题意:给定一个数 n,和一个集合 m,问你小于的 n的所有正数能整除 m的任意一个的数目. 析:简单容斥,就是 1 个数的倍数 - 2个数的最小公倍数 + 3个数的最小公倍数 + ...(-1)^(n ...

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

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

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

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

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

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

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

  9. HDU How many integers can you find 容斥

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

  10. How many integers can you find(容斥+dfs容斥)

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

随机推荐

  1. linux elasticsearch-5.1.1的安装

    (一)下载elasticsearch linux安装包 https://www.elastic.co/downloads/past-releases,然后解压,然后要有对应的java8,即必须先安装j ...

  2. 【python-opencv】16-图像平滑

    [微语]“你以后向成为什么样的人?”    “什么意思,难道我以后就不能成为我自己吗?”    ----<阿甘正传> 补充知识点:如何理解图像的低频是轮廓,高频是噪声和细节 图像的频率:灰 ...

  3. openssl配置

    1.update openssl yum update openssl 2.修改openssl配置 vim /etc/ssh/sshd_config RSAAuthentication yesPubk ...

  4. sql server递归日期

    在做项目任务时,需要将一个日期范围转换为日期表. 例如:日期范围(2017年01月21日~2017年02月20日).转换成一日为单位的日期表,如下. 2017-01-21 2017-01-22 201 ...

  5. mysql python pymysql模块 获取插入的最后一条数据的自增ID lastrowid()方法

    调用游标下的lastrowid 可以获取插入之前的表里id字段存放到哪个自增id cursor.lastrowid mysql> select * from userinfo; +----+-- ...

  6. 2018中国(深圳)IT领袖峰会马化腾演讲全文《数字中国的机遇与探索》

    我们今天大会的主题是数字中国,也佩服我们吴鹰主席在十年前就想到发展的趋势,这么早就把我们联合会取名数字中国.昨天有一个闭门会议,有相当大的篇幅大家都谈了科技.谈创新,大家觉得科技的威力和优势越来越明显 ...

  7. const与常量,傻傻分不清楚~

    当数组的长度在运行中才能够确定时,普通的静态数组无法满足要求,此时需要动态数组来实现. 今天突然想,const变量在初始化时可以接受变量的赋值,那么可不可以用它来定义一个静态数组呢?于是有下面的尝试: ...

  8. [vue]vue双向绑定$on $emit sync-模态框

    双向绑定实现($on $emit) 关于父子之间数据更新同步, 如果单向绑定, 子修改了,父却没有修改, 这种一般不符合规范 正常更新数据的套路是: 1. 子通知父更新数据 2. 子自动刷新获取最新数 ...

  9. 【转】SVM入门(一)SVM的八股简介

    (一)SVM的八股简介 支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本.非线性及高维模式识别中表现出许多特有的优势,并能够 ...

  10. 026-chmod命令

    语法# chmod [ 选项参数 ]  选择修改权限的对象   权限的改变   目标文件 语义:对哪些目标文件的哪些权限进行修改. (1)# chmod -R ugo +r /home/apple.将 ...