题意

就是给出一个整数n,一个具有m个元素的数组,求出1-n中有多少个数至少能整除m数组中的一个数

(1<=n<=10^18.m<=20)

题解

这题是容斥原理基本模型。

枚举n中有多少m中元素的个数,在结合LCM考虑容斥。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const long long N=;
long long a[N],n,m,ans;
long long gcd(long long x,long long y){
if(y==)return x;
else return gcd(y,x%y);
}
long long lcm(long long x,long long y){
return x/gcd(x,y)*y;
}
void dfs(long long now,long long num,long long res,long long k){
if(res==){
if(num==)return;
long long tmp=n/num;
if(k&)ans+=tmp;
else ans-=tmp;
return;
}
if(now==m+)return ;
if(lcm(num,a[now])<=n)dfs(now+,lcm(num,a[now]),res-,k);
dfs(now+,num,res,k);
}
int main(){
while(scanf("%lld%lld",&n,&m)!=EOF){
n--;
for(long long i=;i<=m;i++)scanf("%lld",&a[i]);
for(long long i=;i<=m;i++)dfs(,,i,i);
printf("%lld\n",ans);
}
}

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 ( 组合数学 容斥原理 二进制枚举)

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

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

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

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

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

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

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

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

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

  9. hdu 1796 How many integers can you find

    容斥原理!! 这题首先要去掉=0和>=n的值,然后再使用容斥原理解决 我用的是数组做的…… #include<iostream> #include<stdio.h> #i ...

随机推荐

  1. Mac-O文件加载的全过程(一)

    在Mac的开发中, 有没有想过当我们点击可执行文件之后,Mac究竟做了什么事情才让我们的程序运行起来? 对于应用层开发人员或者普通的用户而言, 其实无需知道的这么详细:但是对于内核开发人员而言, 如果 ...

  2. Redis - Python操作Redis

    目录 Python操作Redis 一. Redis安装和基本使用 二. Python操作Redis API使用 1.操作模式 2.连接池 3.Django配置Redis 4.操作 Python操作Re ...

  3. 通过CSS样式隐藏百度版权标志

    在JSP中添加: //隐藏所有.anchorBL{ display:none; } //隐藏下方的保留百度地图图片 .BMap_cpyCtrl{ display:none; }   注:维护他人版权, ...

  4. Ajax原理-重点

    Ajax原理 AJAX即“Asynchronous Javascript And XML”,是指一种创建交互式网页应用的网页开发技术.AJAX 是一种用于创建快速动态网页的技术.它可以令开发者只向服务 ...

  5. Having用法

    HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELECT 的交互方式类似.WHERE 搜索条件在进行分组操作之前应用:而 HAVING 搜索条件在进行分组操作之后应用 ...

  6. Maven学习总结(23)——Maven常用命令介绍

    1.生成eclipse项目:mvn eclipse:eclipse 2.清除eclipse的一些系统设置:mvn eclipse:clean 3.mvn tomcat:run 在tomcat里面运行 ...

  7. [Angular + Unit Testing] Mock HTTP Requests made with Angular’s HttpClient in Unit Tests

    In a proper unit test we want to isolate external dependencies as much as possible to guarantee a re ...

  8. (手冊)Animation 之 使用Animation View

    观看游戏物体上的动画(Viewing Animations on a GameObject) Animation View 是与 Hierarchy View.Scene View和Inspector ...

  9. 算法 - 求一个数组的最长递减子序列(C++)

    //************************************************************************************************** ...

  10. JUnit4.8.2源码分析-4 RunNotifier与RunListener

    JUnit4运行过程中,org.junit.runner.notification. RunListener和RunNotifier运用了观察者模式. 1.观察者 观察者Observer/Listen ...