//设置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. Setup Git Server in CentOS 6.3

    0. Environment: Server machine: CentOS 6.3 x86 Client machine: Windows 10 Pro x86_64 1. Install ssh ...

  2. Android分屏显示LogCat

    Eclipse里有非常多界面组件,文件列表.编辑区.类结构等等,在这么多界面组件里,再打开一个Logcat就基本没有什么空间了.与其挤在一起还不如分开成两个窗体. 或者你有两个屏幕,想一个屏幕编辑,一 ...

  3. hdu2175汉诺塔IX

    汉诺塔IX Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  4. Codeforces Round#309 C Kyoya and Colored Balls

    给定一个k表示颜色的种类从1到k 然后接下来k行, 每行一个数字, 代表该颜色的球有多少个 这些球都放在一个包中,然后依次拿出.  要求颜色i的最后一个球, 必须要排在颜色i+1的最后一个球前面,   ...

  5. [Cacti] cacti监控mongodb性能实战

    .生成监控图 在界面.选择"Device".选择mongodb服务器连接"3.X2_mongodb".再选择右上角的"Create Graphs fo ...

  6. uva live 4394 String painter 间隔dp

    // uva live 4394 String painter // // 问题是,在培训指导dp运动主题,乍一看,我以为只是一点点复杂 // A A磕磕磕,两个半小时后,.发现超过例子.然而,鉴于他 ...

  7. [PATCH] UBUNTU: SAUCE: (no-up) apparmor: Sync to apparmor3 - RC1(v3.4.x kernel)

    ubuntu touch v3.4 kernel AppArmor v3 backport patch 地址1:https://github.com/multirom-aries/ubuntu-pho ...

  8. 经典排序算法 - 归并排序Merge sort

    经典排序算法 - 归并排序Merge sort 原理,把原始数组分成若干子数组,对每个子数组进行排序, 继续把子数组与子数组合并,合并后仍然有序,直到所有合并完,形成有序的数组 举例 无序数组[6 2 ...

  9. OCP-1Z0-051-名称解析-文章7称号

    7. Which two  statements are true regarding the USING and ON clauses in table joins? (Choose two.) A ...

  10. 【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三】动手绑定自己定义类至Lua

        查看[Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之二]新建项目中配制环境,我们完美的在新建项目中完毕了绑定须要的环境,接下来才是最关健的一步.绑定自己定义C++类至Lu ...