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 K (Java/Others)
Total Submission(s): 6434 Accepted Submission(s): 1849
all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.
12 2
2 3
7 这道题目是给定了因子,而且还不是互质的, 所以在容斥原理上,就不能简单想乘,要求最小公倍数LCM 另外有可能因子为0#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h> using namespace std;
typedef long long int LL;
LL gcd(LL a,LL b)
{
return b?gcd(b,a%b):a;
}
LL ans,a[15],n,m;
void dfs(int id,int flag,int lcm)
{
lcm=a[id]/gcd(a[id],lcm)*lcm;
if(flag)
ans+=n/lcm;
else
ans-=n/lcm;
for(int i=id+1;i<m;i++)
dfs(i,!flag,lcm);
}
int main()
{
while(cin>>n>>m)
{
n--;
for(int i=0;i<m;i++)
{
scanf("%d",&a[i]);
if(!a[i]) i--,m--;
}
ans=0;
for(int i=0;i<m;i++)
dfs(i,1,a[i]);
printf("%lld\n",ans);
}
return 0;
}
HDU 1796 How many integers can you find(容斥原理)的更多相关文章
- HDU 1796 How many integers can you find(容斥原理)
题意 就是给出一个整数n,一个具有m个元素的数组,求出1-n中有多少个数至少能整除m数组中的一个数 (1<=n<=10^18.m<=20) 题解 这题是容斥原理基本模型. 枚举n中有 ...
- HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- 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 容斥入门
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(容斥原理+二进制/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 容斥第一题
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 ...
随机推荐
- PL/SQL 美化器不能解析文本
1.问题:PL/SQL美化器不能解析文本 原始sql语句如下: CREATE OR REPLACE VIEW V_GGXZBM AS SELECT XZBM,XZMC,CASE WHEN PARENT ...
- jqgrid 加按钮列
1.在jqgrid表格中增加列,内容是图标,定义图标单击事件,可以操作这一行的数据,如下图 2.前台代码 <div id="grid_List"> <table ...
- springboot常见异常解决方案
1.@Transactional类注入失败 spring的代理模式有2种::java自带的动态代理模式和cglib代理模式,默认情况下使用的java自带的代理模式. 对于这2种模式,java自带的适用 ...
- python打包exe文件-ImportError: No module named 'queue'
我之前遇到的一个错误就是 File "site-packages\urllib3\packages\six.py", line 92, in __get__ File " ...
- chrome 浏览器设置字体大小,方便调试
H5开发的时候,有时候明明字体没有那么大,但在chrome中看上去依然很大.就像型号不对一样,但在手机端是正常的. 这是因为chrome浏览器设置了默认字体.只需要设置一下即可. 「chrome:/ ...
- 如果你需要从不同的服务器(不同域名)上获取数据就需要使用跨域 HTTP 请求
Response.AppendHeader("Access-Control-Allow-Origin", "*")Response.AppendHeader(& ...
- 3.selenium模块
本节内容: 介绍 安装 基本使用 选择器 等待元素被加载 元素交互操作 其他 项目练习 一.介绍 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行Ja ...
- 使用 xlue 实现 tips
经常遇到如下的需求 鼠标hover到目标对象一定时间后,弹出tips或者窗口; 鼠标离开目标对象一定时间后,隐藏tips或者窗口; 鼠标从目标对象移动到弹出的窗口上,这种状况下不隐藏窗口; 考虑到这种 ...
- CentOS6.2下安装中文输入法
因为在程序中需要输入中文,但是系统没有预装中文输入法,所以就安装一下,顺便记录 1.用root登录 ,或su root2.yum install "@Chinese Support" ...
- webpack相关资料
百度webpackhttps://www.zhihu.com/question/39290543http://xingdongpeng.com/2016/08/15/webpack-%E6%80%BB ...