HDU How many integers can you find 容斥
How many integers can you find
Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4249 Accepted Submission(s):
1211
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.
line contains two integers N and M. The follow line contains the M integers, and
all of them are different from each other. 0<N<2^31,0<M<=10, and the
M integer are non-negative and won’t exceed 20.
2 3
略坑略坑。
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; bool Hash[];
int f[],len,qlen;
__int64 Q[]; int gcd(int a,int b)
{
if(a<)a=-a;
if(b<)b=-b;
if(b==)return a;
int r;
while(b)
{
r=a%b;
a=b;
b=r;
}
return a;
}
void solve(__int64 m)
{
qlen = ;
Q[]=-;
for(int i=;i<=len;i++)
{
int k=qlen;
for(int j=;j<=k;j++)
Q[++qlen]=-*(Q[j]*f[i]/gcd(Q[j],f[i]));
}
__int64 sum = ;
for(int i=;i<=qlen;i++)
sum = sum+m/Q[i];
printf("%I64d\n",sum);
}
int main()
{
int m,x;
__int64 n;
while(scanf("%I64d%d",&n,&m)>)
{
n=n-;
memset(Hash,false,sizeof(Hash));
for(int i=;i<=m;i++)
{
scanf("%d",&x);
Hash[x]=true;
}
for(int i=;i<=;i++)
{
if(Hash[i]==true)
for(int j=i+i;j<=;j=j+i)
if(Hash[j]==true) Hash[j]=false;
}
len = ;
for(int i=;i<=;i++)if(Hash[i]==true) f[++len]=i;
solve(n);
}
return ;
}
HDU How many integers can you find 容斥的更多相关文章
- hdu 1796 How many 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 容斥第一题
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 (容斥)
题意:给定一个数 n,和一个集合 m,问你小于的 n的所有正数能整除 m的任意一个的数目. 析:简单容斥,就是 1 个数的倍数 - 2个数的最小公倍数 + 3个数的最小公倍数 + ...(-1)^(n ...
- How many integers can you find(容斥+dfs容斥)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥
Senior PanⅡ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Pr ...
- HDU - 5297:Y sequence (迭代&容斥)
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hat ...
- Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- HDU - 4336:Card Collector(min-max容斥求期望)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- HDU - 5977 Garden of Eden (树形dp+容斥)
题意:一棵树上有n(n<=50000)个结点,结点有k(k<=10)种颜色,问树上总共有多少条包含所有颜色的路径. 我最初的想法是树形状压dp,设dp[u][S]为以结点u为根的包含颜色集 ...
随机推荐
- poj 1176 Party Lamps
http://poj.org/problem?id=1176 Party Lamps Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- [原创] 关于quartz (spring 中的任务调度器)时间配置
1. CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 ...
- bzoj1834 [ZJOI2010]network 网络扩容
第一问跑最大流,第二问新建一条边连接0和1,流量为上第一问的答案+k,费用为0,接下来图中每条边拆成两条边,第一条容量为C费用为0,第二条容量无穷费用为W,再跑一遍费用流即可. 代码 #include ...
- bzoj1758 [Wc2010]重建计划 & bzoj2599 [IOI2011]Race
两题都是树分治. 1758这题可以二分答案avgvalue,因为avgvalue=Σv(e)/s,因此二分后只需要判断Σv(e)-s*avgvalue是否大于等于0,若大于等于0则调整二分下界,否则调 ...
- drds 广播表的创建以及使用
创建表 , 关键词 : BROADCAST CREATE TABLE `financial_product_yjw` ( `ID` int(10) unsigned NOT NULL AUTO_INC ...
- linux添加字体的过程
只说一下过程, 至于具体的原理还没搞明白. 1. 首先你要有字体文件,ttf或者ttc格式的均可以 我们可以从windows的 C:\WINDOWS\Fonts\ 这个目录下的字体文件复制出来,例如我 ...
- 给debian安装xfce桌面套装
首先要有一个debian的基本系统,然后: 1.sudo apt-get install xorg slim xfce4 #xdm 由于目前源里面最新的版本是4.3.99,想安装4.4 ...
- 在Debian下安装ibus输入法
sudo apt-get install ibus ibus-pinyin im-switch sudo apt-get install ibus-googlepinyin im-switch -s ...
- cvWaitKey();
1.函数形式:int cvWaitKey(int delay=0 ): 函数功能:cvWaitKey()函数的功能是不断刷新图像,频率时间为delay,单位为ms. 参数: delay——— ...
- android 学习随笔三(测试与单元测试框架)
测试 1.按岗位: 黑盒测试:测试业务逻辑 白盒测试:测试逻辑方法 2.按测试粒度 方法测试 function 单元测试 unit 集成测试 integration 系统测试 system 3.按暴力 ...