//设置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. Android Ant 和 Gradle 打包流程和效率对照

    一.Ant 打包:(下载ant.配置环境变量就不说了) 1.进入命令行模式,并切换到项目文件夹.运行例如以下命令为ADT创建的项目加入ant build支持: android update proje ...

  2. 搭建solr单机版

    solr单机版的搭建 一.solr单机版的搭建 1.运行环境 solr 需要运行在一个Servlet容器中,Solr4.10.3要求jdk使用1.7以上,Solr默认提供Jetty(ja),本教va写 ...

  3. Custom Media Player in WPF (Part 1)

    First of all I would like to welcome everyone to my new blog and wish you all a happy new year… Thro ...

  4. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  5. Windows 8 应用开发 - 磁贴

    原文:Windows 8 应用开发 - 磁贴      我们开发的应用在Win8 界面中会以磁贴形式展现,默认情况下磁贴会显示应用图标,即项目工程中的Logo.png图片文件.开发人员可按应用的需要使 ...

  6. C++习题 对象转换

    [Submit][Status][Web Board] Description 定义一个Teacher(教师)类(教师号,姓名,性别,薪金)和一个Student(学生)类(学号,姓名,性别,成绩),二 ...

  7. ibatis实战之OR映射

    相对Hibernate等ORM实现而言,ibatis的映射配置更为简洁直接,以下是一个典型的配置文件. <?xml version="1.0" encoding=" ...

  8. window忘记密码怎么办

    net命令   Net User 功能:添加或更改用户帐号或显示用户帐号信息. 格式:net user [username [password | *] [options]] [/domain] ne ...

  9. HDoj-2084-号码塔-dp

    号码塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  10. lsb_release: command not found 解决方法(转)

    问题:通过lsb_release -a 是查看linux系统版本时报错,具体的解决办法如下: [root@localhost ~]# lsb_release -a-bash: lsb_release: ...