//设置m,Q小于n可以设置如何几号m随机多项整除

//利用已知的容斥原理

//ans = 数是由数的数目整除 - 数为整除的两个数的数的最小公倍数 + 由三个数字。。。

#include<cstdio>

#include<cstring>

#include<iostream>

using namespace std ;

const int maxn = 110 ;

typedef __int64 ll ;

int a[maxn] ;

int len ;

int n , m ;

ll gcd(ll a , ll b)

{

    if(b == 0)

    return a ;

    return gcd(b, a%b) ;

}

int dfs(int pos , ll lcm)

{

    int ans = 0 ;

    for(int i = pos ;i <= len;i++)

    {

        ll lcm_n = lcm*a[i]/gcd(lcm , a[i]) ;//最小公倍数可能会爆int,被坑了一下

        ans += (n-1)/lcm_n - dfs(i+1 , lcm_n) ;

    }

    return ans ;

}

int main()

{

    while(~scanf("%d%d" , &n , &m))

    {

        len = 0 ;

        for(int i = 1;i <= m;i++)

        {

            int t ;

            scanf("%d" , &t) ;

            if(!t) continue ;//可能会有0

            a[++len] = t ;

        }

       int ans = dfs(1 , 1) ;

       printf("%d\n" , ans) ;

    }

    return  0 ;

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

hdu1796 How many integers can you find的更多相关文章

  1. hdu1796 How many integers can you find 容斥原理

    Now you get a number N, and a M-integers set, you should find out how many integers which are small ...

  2. Hdu1796 How many integers can you find 2017-06-27 15:54 25人阅读 评论(0) 收藏

    How many integers can you find Time Limit : 12000/5000ms (Java/Other)   Memory Limit : 65536/32768K ...

  3. HDU1796 How many integers can you find(容斥原理)

    题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ...

  4. HDU1796 How many integers can you find【容斥定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包 ...

  5. 容斥原理学习(Hdu 4135,Hdu 1796)

    题目链接Hdu4135 Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. How many integers can you find(hdu1796)

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

  7. [LeetCode] Sum of Two Integers 两数之和

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  8. [LeetCode] Divide Two Integers 两数相除

    Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...

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

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. Mysql学习笔记(一)数据类型

    原文:Mysql学习笔记(一)数据类型 学习内容: Mysql基本数据类型. 1.数字类型.. i.整型     Mysql数据类型             含义(有符号)     tinyint(m ...

  2. Android_declare-styleable_自己定义控件的属性

    1.简单实例 (1).在res/values文件下定义一个attrs.xml文件 <? xml version="1.0" encoding="utf-8" ...

  3. 自由HTML5串行来到《HTML5具体解释Web开发的例子》连载(三)DOCTYPE和字符集

    于2.1.2通过新老科DOCTYPE控制,读者可以清晰地看到HTML 5精简旧体制的努力取得. DOCTYPE主要用于在开始的情况下,XML于,用作叙述性说明XML同意使用的元素.物业和安排.起初HT ...

  4. tcpdump VS tshark用法(转)

    Tcpdump是网络协议分析的基本工具.tshark是大名鼎鼎的开源网络协议分析工具wireshark (原名叫ethereal)的命令行版本,wireshark可对多达千余种网络协议进行解码分析.W ...

  5. POJ 1798 Truck History

    Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for v ...

  6. 大约apache 2.4.X虚拟主机配置问题的版本号后,

    重装系统,习惯性下载最新的wamp2.5,在各种配置,然后一切正常反应.数据库,代码. 然后打开浏览器,尼嘛,幸运的是,昨天,与虚拟域,其实403该. apache error log的信息是:AH0 ...

  7. 利用Eclipse中的Maven构建Web项目(三)

    利用Eclipse中的Maven构建Web项目 1.将Maven Project转换成动态Web项目,鼠标右键项目,输入"Project Facets" 2.依据Dynamic W ...

  8. c# winform 引用sqlite.dll 运行报错解决方法

    错误信息 :  未能加载文件或程序集“System.Data.SQLite, Version=1.0.81.0, Culture=neutral, PublicKeyToken=db937bc2d44 ...

  9. 【Android进阶】Application对象的详解

    1:Application是什么? Application和Activity,Service一样,是android框架的一个系统组件,当android程序启动时系统会创建一个 application对 ...

  10. cocos2dx lua

    对于游戏公司而言.採用游戏脚本lua.python等进行开发也非经常见,可是非常多童鞋对脚本并没有非常熟悉的概念,本篇则向大家简介脚本的用途以及在Cocos2dx基础使用方法: Lua和python这 ...