HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
题意分析
求在[1,n-1]中,m个整数的倍数共有多少个
与 UVA.10325 The Lottery 一模一样。
前置技能和其一样,但是需要注意的有一下几点:
1. m个数字中可能有0
2. 要用long long
代码总览
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define nmax 20
#define ll __int64
using namespace std;
ll initnum[nmax];
ll n;
int m;
ll gcd(ll a, ll b)
{
if(!b) return a;
else return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
return a/abs(gcd(a,b))*b;
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%I64d %d",&n,&m) != EOF){
int num = 0;
ll temp = 0;
for(int i = 0 ;i<m;++i){
scanf("%I64d",&temp);
if(temp !=0) initnum[num++] = temp;
}
ll time = (1<<num);
ll ans = 0;
n--;
for(int i = 1; i<time;++i){
int index = 0;
ll tmpans = 1LL;
for(int j = 0; j<num;++j){
if( 1 & (i>>j)){
tmpans = lcm(tmpans,initnum[j]);
index++;
}
}
if(index & 1){//add
ans += n / tmpans;
}else{//even
ans -= n / tmpans;
}
}
//ans = n-ans;
printf("%I64d\n",ans);
}
return 0;
}
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)的更多相关文章
- 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 ...
- HDU 1796 How many integers can you find(容斥原理)
题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description ...
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- hdu 1796 How many integers can you find
容斥原理!! 这题首先要去掉=0和>=n的值,然后再使用容斥原理解决 我用的是数组做的…… #include<iostream> #include<stdio.h> #i ...
- HDU 1796 How many integers can you find 【容斥】
<题目链接> 题目大意: 给你m个数,其中可能含有0,问有多少小于n的正数能整除这个m个数中的某一个. 解题分析: 容斥水题,直接对这m个数(除0以外)及其组合的倍数在[1,n)中的个数即 ...
随机推荐
- 私有云搭建:树莓派+kodexplorer可道云,几步搞定!
目前蒲公英异地组网则是推出了树莓派1.0软件客户端.无需公网IP!简单60秒设置!轻松远程访问树莓派!实现远程登录.远程配置.远程访问服务.传输数据等等操作.例如:蒲公英树莓派1.0软件客户端+可道云 ...
- 利用Python编写Windows恶意代码!自娱自乐!勿用于非法用途!
本文主要展示的是通过使用python和PyInstaller来构建恶意软件的一些poc. 利用Python编写Windows恶意代码!自娱自乐!勿用于非法用途!众所周知的,恶意软件如果影响到了他人的生 ...
- 读取classpath配置文件的方法
http://www.cnblogs.com/sprinng/p/5622600.html
- scanf() scanf_s() 区别
写博原因:这几天由于小学期的缘故,接触到了好多C代码,在VS2013中编译的时候,遇到了如下问题: 错误 1 error C4996: 'scanf': This function or variab ...
- Week2-作业1
第一章:引用:如果一架民用飞机上有一个功能,用户使用它的概率是百万分之一,你还要做这个功能么? 选择之后,这个功能是什么呢?谜底是飞机的安全功能. 个人认为,飞机的安全功能这个 ...
- SCRUM:第一、二天任务实现情况
在团队项目“广商百货”的SCRUM项目中我认领的任务: LOGO设计 5.18熬夜完成LOGO设计(投票通过): 设计理念: 1.全矢量图设计,适应各种超大尺寸使用: 2.3D化透视设计,简约视效,也 ...
- JPEG标准推荐的亮度、色度DC、AC Huffman编码表
JPEG 标准推荐的亮度.色度DC.AC Huffman 编码表 博主在完成数字图像处理大作业时利用搜索引擎查找了很久完整的四张Huffman 编码表(亮度AC Huffman编码表.亮度DC Huf ...
- modify headers插件的使用
Modity headers是firefox浏览器的一个插件,作用是改变http请求的IP地址 (一)在firefox中添加该插件 步骤一:打开firefox浏览器,打开地址: https://add ...
- [转帖] go的import 语法
package 的导入语法写 Go 代码的时经常用到 import 这个命令用来导入包,参考如下: import( "fmt" ) 然后在代码里面可以通过如下的方式调用: fmt. ...
- [微软官方]FSUTIL
Applies To: Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, Windows Server 2003 ...