容斥原理练习题,忘记处理gcd 和 lcm,wa了几发0.0.

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll Num[];
ll gcd(ll a,ll b)
{
return b == ? a : gcd(b,a%b);
}
int main()
{
ll N, M;
while(scanf("%lld%lld",&N,&M)!=EOF)
{
N--;
ll num = ;
ll tmp,Cnt = ;
for(int i = ; i < M; ++i)
{
scanf("%lld",&tmp);
if(tmp == ) continue;
else {
Num[Cnt++] = tmp;
}
}
for(int i = ; i < ( << Cnt) ; ++i)
{
ll cnt = , tmp = ;
for(int j = ; j < Cnt; ++j)
{
if(i & ( << j))
{
cnt++;
tmp =tmp /gcd(tmp,Num[j]) * Num[j];
}
//printf("%lld\n",tmp);
}
if(cnt & ) num += (N/tmp);
else num -= (N/tmp);
}
printf("%lld\n",num);
}
return ;
}

HDU 1796 (容斥原理)的更多相关文章

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

    题目连接   http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理  纪念一下  TMD看了好久才明白DFS... 先贴代码后解释 #includ ...

  2. HDU 1796 容斥原理

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

  3. hdu 1796(容斥原理+状态压缩)

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

  4. How many integers can you find HDU - 1796 容斥原理

    题意: 给你一个数n,找出来区间[1,n]内有多少书和n不互质 题解: 容斥原理 这一道题就让我真正了解容斥原理的实体部分 "容斥原理+枚举状态,碰到奇数加上(n-1)/lcm(a,b,c. ...

  5. HDU 1796 How many integers can you find (状态压缩 + 容斥原理)

    题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...

  6. HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)

    HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...

  7. GCD HDU - 1695 容斥原理(复杂度低的版本)

    题意: 让你从区间[a,b]里面找一个数x,在区间[c,d]里面找一个数y.题目上已经设定a=b=1了.问你能找到多少对GCD(x,y)=k.x=5,y=7和y=5,x=7是同一对 题解: 弄了半天才 ...

  8. - Visible Trees HDU - 2841 容斥原理

    题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前 ...

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

    题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description    ...

随机推荐

  1. 从零开始搭建高性能高可用Tomcat服务器

    目标: Tomcat+Nginx+Memcached Ubuntu 16.04 64位测试通过 动静分类.负载均衡.集群.Javolution序列化.高性能.高可用 配置环境(目前均为最新稳定版): ...

  2. Python正则的贪婪和非贪婪示例

    贪婪匹配 import re info = """ saas12 [STREAM] codec_type=audio111 [/STREAM]-- [STREAM] co ...

  3. Hadoop生态组件的WebUI地址

    ================================Impala 相关================================ Impala的常用端口: jdbc/ODBC 端口: ...

  4. TTS与MediaPlayer混合使用

    package com.xxx.xxx.Util; import android.content.Context; import android.media.MediaPlayer; import a ...

  5. spring注解第03课 按条件加载Bean @Conditional

    package com.atguigu.config; import org.springframework.context.annotation.Bean; import org.springfra ...

  6. 多态(upcast)减少分支判断 以及 多态继承设计、具体类型判断。

    Influenced by <java 八荣八耻>,翻了下<java编程思想> 印象中多态产生的条件:1.子类继承父类 2.父类[指针]指向子类 3.父类引用调用重写(@Ove ...

  7. PHP面向对象的三大特征操作——封装、继承、多态(下)

    <?php 继承(单继承)特点:一个子类只有一个父类,一个父类可以有多个子类.//父类(基类)class Ren{    public $name;    public function say ...

  8. 卷积中的full、same、valid

    通常用外部api进行卷积的时候,会面临mode选择. 本文清晰展示三种模式的不同之处,其实这三种不同模式是对卷积核移动范围的不同限制. 设 image的大小是7x7,filter的大小是3x3     ...

  9. ubuntu 18.04//18.10&&windows 7/10双系统系统时间不一致

    新版本的Ubuntu使用systemd启动之后,时间也改成了由timedatectl来管理,因此网上的许多方法就不适用了. 经过测试发现下面的方法可以解决双系统时间不一致问题: 1.将硬件时间UTC改 ...

  10. 洛谷P2699小浩的幂次运算

    二分走一波,没想到题解的大佬做法 p_q 注意爆long long,所以先对数取一下上限 二分确定下限,然后输出 #include<stdio.h> #include<math.h& ...