Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.

题目大意:给你一个数n,和m个0~20的整数i,让你求1~n-1中是i的倍数的数有几个。

显然,这是一个容斥定理的题,求对1~(n-1)中所有m个i的倍数的数的个数。并且m<=10,因此我们用二进制枚举法就能够列出所有的情况。

需要注意的就是m个数,把这m个数先化成互质的。最后在套用模板即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[];
int main()
{
ll n, m;
while(~scanf("%lld%lld",&n,&m))
{ int top = ;
for(int i = ; i < m; ++ i)
{
ll x;
cin >> x;
if(x != )
a[top++] = x;
}
ll ans = ,sum,num;
for(int i = ; i < ( << top); ++ i)
{
num=,sum=;
for(int j = ; j < top; ++ j)
{
if((i >> j) & )
{
num++;
sum = sum * a[j] /(__gcd(sum, a[j]));
}
}
if(num % )
{
ans += (n - ) / sum;
}
else
{
ans -= (n - ) / sum;
}
}
cout << ans << endl;
}
return ;
}

以上。

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

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

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

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

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

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

  4. Leetcode Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 不用乘.除.求余操作,返回两整数相除的结果,结 ...

  5. LeetCode Sum of Two Integers

    原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...

  6. Nim Game,Reverse String,Sum of Two Integers

    下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...

  7. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  8. LeetCode 371. Sum of Two Integers

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

  9. leetcode-【中等题】Divide Two Integers

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

  10. 解剖SQLSERVER 第十三篇 Integers在行压缩和页压缩里的存储格式揭秘(译)

    解剖SQLSERVER 第十三篇    Integers在行压缩和页压缩里的存储格式揭秘(译) http://improve.dk/the-anatomy-of-row-amp-page-compre ...

随机推荐

  1. P2663 越越的组队

    原题链接  https://www.luogu.org/problem/P2663 很容易看出来是个背包问题嘛: 体积是总分的一半,求最高分,每个同学选或不选,是个 01背包问题. 自信地交上去之后发 ...

  2. mysql8.0.17gtid方式实现主从同步

    数据库的安装: [root@node1 8.0.17]# rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm 警告:mysql-commun ...

  3. Hdu5762

    Hdu5762 题意: 你n个点,让你找两个数对,A,B和C,D,使得A和B的曼哈顿距离等于C和D的曼哈顿距离,问是否存在这样的对,A!=C且B!=D. 解法: 直接暴力判断,时间复杂度是 $ O(n ...

  4. intle官方手册下载

    如题:https://software.intel.com/en-us/articles/intel-sdm#three-volume 方便哪些不会怎么搜索的同学吧. 链接: https://pan. ...

  5. yum install 报错

    把python2升级到python3以后,yum报错: [root@localhost Python-]# yum install openssl File except KeyboardInterr ...

  6. 互联网IT当线上出现 bug 时,是怎么处理的?

    线上BUG说处理方法:1.关于线上BUG问题,目前公司有一整套线上故障流程规范,包括故障定义.定级.处理流程.故障处理超时升级机制.故障处理小组.故障处罚(与故障存在时长有关)等:2.最主要的是,线上 ...

  7. 重读APUE(11)-信号安全的可重入函数

    重入时间点 进程捕捉到信号并对其进行处理时,进程正在执行的正常指令序列就会被信号处理程序临时中断,它首先执行该信号粗合理程序中的指令:如果从信号处理程序返回,则继续执行捕捉到信号时进程正在执行的正常指 ...

  8. IDEA 好用的插件

    IDEA 好用的插件 非自带的一些自用插件. Alibaba java Coding Guidelines 阿里出的java规范,支持eclipse和Idea,支持实时扫描,规范代码,养成良好习惯.推 ...

  9. OpenCL多次循环执行内核的一个简单样例

    最近有不少朋友在多次循环执行OpenCL内核程序的时候碰到一些问题.由于对OpenCL初学者而言可能比较普遍,因此我这里给出一个清晰简单的demo来掩饰如何简单又高效地执行循环执行OpenCL内核. ...

  10. 【JS新手教程】弹出两层div,及在LODOP内嵌上层

    前面的博文有个简单的弹出div层[JS新手教程]浏览器弹出div层1,有一层,不过为了提示,一般会不让用户可以点击该提示之外的地方的.如果让用户弹出层后,把其他的按钮和链接都设置不可用应该比较麻烦,如 ...