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为根的包含颜色集 ...
随机推荐
- ACM之Java速成(2)
acm中Java的应用 Chapter I. Java的优缺点各种书上都有,这里只说说用Java做ACM-ICPC的特点: (1) 最明显的好处是,学会Java,可以参加Java Challenge ...
- 常见的appbug(转)
移动App Bug的影响是用户体验差.App的商店评级下降.用户换用竞争对手的App,声誉和信誉损失.最后销售量减少,如果它是一个付费App的话. 移动App测试与传统台式机测试相比有一定的复杂性.这 ...
- HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)
Problem Description There is an old country and the king fell in love with a devil. The devil always ...
- C语言 类型
int 2个字节或4个字节 根据平台而定, -32,768 到 32,767 或 -2,147,483,648 到 2,147,483,647 unsigned int 2或4个字节 0到655 ...
- JS获取项目根目录
function getRootPath(){ //获取当前网址,如: http://localhost:8088/test/test.jsp var curPath=window.document. ...
- 基于fullpage的幻灯片播放
<!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...
- Script to compile invalid objects in DB
REM: Script to compile invalid objects in DB after refreshing REM: REM:***************************** ...
- Java中的数组操作进阶
package com.mi.array; import java.util.Arrays; /** * System.arraycopy(i, 0, j, 0, i.length);这种复制会覆盖目 ...
- 夺命雷公狗---node.js---3commonJs 与 nodeJs的简介
JavaScript是一个强大面向对象语言,它有很多快速高效的解释器.官方JavaScript标准定义的API是为了构建基于浏览器的应用程序.然而,并没有定于一个用于更广泛的应用程序的标准库. Com ...
- RobotFrameWork接口报文测试-----(一)简单demo的实现
最近几个月的工作任务都是通过使用RF工具来搭建服务器端接口的自动化测试,使用python作为2次开发的语言,也是第一次去做这种项目,经验善浅,还是很有可能会走很多的弯路,为此,我希望自己能把每个阶段的 ...