hdu How many integers can you find
题意:找出小于n是m个数每个数的倍数的数的个数。
思路:用二进制表示是那几个数的倍数。 二进制进行容斥,去掉小于0的数。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; __int64 n,m,g;
__int64 a[],b[]; __int64 gcd(__int64 a,__int64 b)
{
return b==?a:gcd(b,a%b);
} int main()
{
while(scanf("%I64d%I64d",&n,&m)!=EOF)
{
memset(a,,sizeof(a));
__int64 cnt=;
for(int i=; i<m; i++)
{
__int64 x;
scanf("%I64d",&x);
if(x)
a[cnt++]=x;
}
__int64 ans=;
for(int i=; i<(<<cnt); i++)
{
__int64 xx=;
__int64 x=;
memset(b,,sizeof(b));
for(int j=; j<cnt; j++)
{
if(i&(<<j))
{
b[xx]=a[j];
xx++;
x*=a[j];
}
}
if(xx>)
{
g=(b[]*b[])/gcd(b[],b[]);
for(int k=; k<xx; k++)
{
g=(g*b[k])/gcd(g,b[k]);
}
x=g;
}
if(xx%!=)
{
ans+=((n-)/x);
}
else
{
ans-=((n-)/x);
}
}
printf("%I64d\n",ans);
}
return ;
}
hdu How many integers can you find的更多相关文章
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- HDU How many integers can you find 容斥
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796How many integers can you find(简单容斥定理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 Howmany integers can you find (容斥原理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 How many integers can you find(容斥原理)
题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description ...
- HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...
- HDU 1796 How many integers can you find 容斥入门
How many integers can you find Problem Description Now you get a number N, and a M-integers set, y ...
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- linux 搭建vpn (pptp)
一.VPN服务器环境说明 操作系统:CentOS release 6.4 (Final) 本地网卡: 复制代码 代码如下: # ifconfig em1 Link encap:Ethernet HWa ...
- 自己去看dubbo源码
编译Dubbo源码并测试 2014.09.24 | Comments 转http://blog.javachen.com/2014/09/24/compile-and-test-dubbo.html ...
- SVN server的搭建
当做大的项目是,svn是代码管理的好工具,假设是用自己的server,那么须要搭建SVNserver. Subversion是一款很优秀的svnserver工具,笔者採用VisualSVN serve ...
- codevs 3305 水果姐逛水果街Ⅱ
/*我尼玛 又一个min打成max 看了半天....*/ #include<iostream> #include<cstdio> #include<cstring> ...
- http2.0
HTTP2.0性能增强的核心:二进制分帧 HTTP 2.0最大的特点: 不会改动HTTP 的语义,HTTP 方法.状态码.URI 及首部字段,等等这些核心概念上一如往常,却能致力于突破上一代标准的性能 ...
- Access数据库数据转换Table.Json
使用WPF组件 xaml <Window x:Class="JsonConvert.MainWindow" xmlns="http://schemas.micros ...
- 【javascript模式】Chapter2: 基本 技巧
1 尽量少用全局变量,最好一个应用程式只有一个全局变量 隐含全局变量(不使用var声明)与明确定义的全局变量区别: (1)使用var创建的全局变量(在函数外部声明)不能用delete删除 (2) ...
- Android虚拟机GenyMotion
GenyMotion:需要VirtualBox,安装后可以选择机型,这个应该是Android for x86的一个改进版虚拟机,在原版的基础上针对不同机型用了和原机型同样的GUI,但是发现缺少了Goo ...
- oracle批量转库工作,比较快捷的方式
select 'create table ' || t.TABLE_NAME || ' as select * from ODS_ZMGLXT.'|| t.TABLE_NAME ||'; ' fr ...
- centos node卸载
1.通过包管理工具 如果是通过包管理工具安装的话,那就和包管理工具卸载 yum remove nodejs npm -y 2.手动 如果是通过手动安装:官方下载后安装 进入到安装的路径 cd /opt ...