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. Integer int auto-boxing auto-unboxing ==

    Auto-boxing 自动装箱 Auto-unboxing 自动拆箱 == 相等 1.new出来的对象,除非遇到了拆箱的情况,肯定不相等. 因为new对象之前需要在JVM堆中提供空间,所以new出来 ...

  2. 爬虫之操作excel

    几种常用模块的使用方法 注释:Excel 2003 即XLS文件有大小限制即65536行256列,所以不支持大文件,而Excel 2007以上即XLSX文件的限制则为1048576行16384列 下面 ...

  3. Hadoop Shell命令字典

    转载自:https://www.aboutyun.com//forum.php/?mod=viewthread&tid=6983&extra=page%3D1&page=1&a ...

  4. java并发编程--第一章并发编程的挑战

    一.java并发编程的挑战 并发编程需要注意的问题: 并发编程的目的是让程序运行的更快,然而并不是启动更多的线程就能让程序最大限度的并发执行.若希望通过多线程并发让程序执行的更快,会受到如下问题的挑战 ...

  5. servlet多线程安全问题

    Servelet多线程安全问题 原因 一个servlet被实例化一次,当有多个用户访问时,多个线程会访问同一个实例,实例变量就会被不同的用户修改. 简单的案例 新建servlet,访问http://l ...

  6. 第11组 Beta冲刺(4/5)

    第11组 Beta冲刺(4/5)   队名 不知道叫什么团队 组长博客 https://www.cnblogs.com/xxylac/p/12018586.html 作业博客 https://edu. ...

  7. DataTable 转换为List

           注意table 列的参数类型,若不为string 需要详细声明 如 typeof(Int32)          public static IList<T> Convert ...

  8. 安装jdk1.8.0_11环境脚本

    安装jdk1.8.0_11的脚本,具体的版本可在脚本中调整,发现最后的重置环境变量没生效,还得再终端界面source /etc/profile [root@ZFVM-APP-- ~]# vim jdk ...

  9. 数据库中的几个概念 - LGWR, ARCH,ASYNC,SYNC,AFFIRM

    双机热备(双机容错)就是对于重要的服务,使用两台服务器,互相备份,共同执行同一服务.当一台服务器出现故障时,可以由另一台服务器承担服务任务,从而在不需要人工干预的情况下,自动保证系统能持续提供服务 双 ...

  10. 执行git pull时提示Connection reset by 13.229.188.59 port 22

    问题如下图: 解决办法: 1. 2. 3. 4. 5. 6.