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 ...
随机推荐
- 在Windows8系统下exe格式会计课件下载播放帮助图解
近期非常多会计从业人员都開始购买课件,開始学习,准备考试:可是网校的课件有些是EXE扩展名格式的,在Windows8系统下播放比較困难.方法比較曲折,这里用图说话,给大家一点參考,希望对大家实用. 下 ...
- Springboot读取配置文件的两种方法
第一种: application.yml配置中的参数: zip: Hello Springboot 方法读取: @RestController public class ControllerTest ...
- IDirect3DDevice9::SetTexture的stage参数
HRESULT IDirect3DDevice9::SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture) 其中Stage并不是“阶段”的意思 ...
- 如果你需要从不同的服务器(不同域名)上获取数据就需要使用跨域 HTTP 请求
Response.AppendHeader("Access-Control-Allow-Origin", "*")Response.AppendHeader(& ...
- 图解PCIE原理(从软件角度)
1 PCIE基本概念 1.1 PCIE拓扑架构图 1.2 PCIE Switch内部结构图 1.3 PCIE协议结构图 2 PCIE枚举原理 2.1 Type0&Type1配置头空间 ...
- ubuntu更新root密码
- PLSQL Develope连接oracle数据库配置
首先我们在讲PLSQL Develope连接oracle数据库配置之前,先讲下如果不用PLSQL Develope连接oracle数据库,那该怎么办,那就是在本机安装oracle数据库,不过这个对于配 ...
- CCNA2.0笔记_二层交换
VLAN上并不需要配置IP地址,除非是出于管理的需要. 基于Vlan的设计原理,即隔离网络的广播域,再者运行STP来提供二层的防环机制:在同一个设备集中不同Vlan之间是无法通信的(在没有三层设备的情 ...
- 转载:JMeter压力测试入门教程[图文]
JMeter压力测试入门教程[图文] Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试但后来扩展到其他测试领域. 它可 ...
- 今天升级netbean出错
出现:无法初始化 UI netbean 由于ubuntun装的是open jdk 直接删除open jdk就可以 sudo apt-get autoremove open-jdk*