题意: 给一个N.然后给M个数,问1~N-1里面有多少个数能被这M个数中一个或多个数整除. 思路: 首先要N-- 然后对于每一个数M 事实上1~N-1内能被其整除的 就是有(N-1)/M[i]个 可是会出现反复 比方 例子 6就会被反复算 这时候我们就须要容斥原理了 加上一个数的减去两个数的.. 这里要注意了 两个数以上的时候 是求LCM而不是简单的相乘! 代码: #include "stdio.h" #include "string.h" #include &qu…
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 The Lottery 一模一样. 前置技能和其一样,但是需要注意的有一下几点: 1. m个数字中可能有0 2. 要用long long 代码总览 #include <cstdio> #include <algorithm> #include <cstring> #incl…
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 } + sum{ 整除三个的数 }………………所以是奇加偶减,而整除 k 个数的数可以表示成 lcm(A1,A2,…,Ak) 的倍数的形式.所以算出最小公倍数, //HDU 1796 #include <cstdio> #include <iostream> #include <…
题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description   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…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6434    Accepted Submission(s): 1849 Problem Description   Now you get a number N, and a M-integers set, you shou…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5556    Accepted Submission(s): 1593 Problem Description   Now you get a number N, and a M-integers set, you shou…
题意 就是给出一个整数n,一个具有m个元素的数组,求出1-n中有多少个数至少能整除m数组中的一个数 (1<=n<=10^18.m<=20) 题解 这题是容斥原理基本模型. 枚举n中有多少m中元素的个数,在结合LCM考虑容斥. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespa…
How many integers can you find Problem Description   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-intege…
容斥原理!! 这题首先要去掉=0和>=n的值,然后再使用容斥原理解决 我用的是数组做的…… #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<string> #include<vector> #define ll __int64 using namespace std;…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description   Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6710    Accepted Submission(s): 1946 Problem Description   Now you get a number N, and a M-integers set, you shou…
<题目链接> 题目大意: 给你m个数,其中可能含有0,问有多少小于n的正数能整除这个m个数中的某一个. 解题分析: 容斥水题,直接对这m个数(除0以外)及其组合的倍数在[1,n)中的个数即可,因为可能会重复计算,所以在叠加的时候进行容斥处理,下面用的是位运算实现容斥. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namesp…
思路:二进制解决容斥问题,就和昨天做的差不多.但是这里题目给的因子不是质因子,所以我们求多个因子相乘时要算最小公倍数.题目所给的因数为非负数,故可能有0,如果因子为0就要删除. 代码: #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #inclu…
题意:给定一个数 n,和一个集合 m,问你小于的 n的所有正数能整除 m的任意一个的数目. 析:简单容斥,就是 1 个数的倍数 - 2个数的最小公倍数 + 3个数的最小公倍数 + ...(-1)^(n+1) * n个数的最小公倍数. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdl…
题目连接   http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理  纪念一下  TMD看了好久才明白DFS... 先贴代码后解释 #include<cstdio> #include<cstring> using namespace std; #define LL long long #define N 11 LL num[N],ans,n; int m,cnt; LL gcd(LL a,LL b) { int t; while…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5664    Accepted Submission(s): 1630 Problem Description   Now you get a number N, and a M-integers set, you shoul…
题意: 给你一个数n,找出来区间[1,n]内有多少书和n不互质 题解: 容斥原理 这一道题就让我真正了解容斥原理的实体部分 "容斥原理+枚举状态,碰到奇数加上(n-1)/lcm(a,b,c..) 碰到偶数减(n-1)/lcm(a,b,c...)" 这个是lcm(a,b,c,,,)可不是他们的乘积.. 注意了... 还有这道题输入会有0 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostr…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7439    Accepted Submission(s): 2200 Problem Description   Now you get a number N, and a M-integers set, you shoul…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6630    Accepted Submission(s): 1913 Problem Description   Now you get a number N, and a M-integers set, you shoul…
题目链接Hdu4135 Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1412    Accepted Submission(s): 531 Problem Description Given a number N, you are asked to count the number of integers betwe…
容斥原理练习题,忘记处理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) { ? a : gcd(b,a%b); } int main() { ll N, M; while(scanf("%lld%lld",&am…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4135 Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1176    Accepted Submission(s): 427 Problem Description Given a number N, you are a…
呃,我竟然傻了,同时被a且b整除的个数为n/(a*b). 其实应该是n/[a,b]才对,是他们的最小公倍数啊... #include <iostream> #include <cstdio> #include <algorithm> using namespace std; __int64 ans; __int64 set[30]; __int64 n; int m; __int64 gcd(__int64 a,__int64 b){ if(b==0) return a…
How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1796 Description   Now you get a number N, and a M-integers set, you should find out how many integers which are sm…
题目链接:Coprime pid=5072"> 题面: Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1181    Accepted Submission(s): 471 Problem Description There are n people standing in a line. Each of t…
A题:A - Eddy's爱好   HDU - 2204 具体思路:如果是求n中,为平方数的有多少个,那么答案肯定是sqrt(n),同理,如果是三次根号的话,那么答案肯定是n的三分之一次方.然后继续按照这个思路来,对于1e18次方的数,最多就是2的64次方,也就是说我们最多枚举大小不超过63的素数就可以了,然后还需要考虑一种情况,比如说6的时候,被素数2算了一遍,然后又被素数3算了一遍,这个地方会有重复的计算,又因为2^(3*5*7)已经超过2的60次方了,所以我们只需要考虑三部分就可以了. A…
LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting from 0) Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].  InputT in the first line, indicating…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4272    Accepted Submission(s): 1492 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y)…
H - Visible Trees Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2841 Description There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) poi…
http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Problem Description   When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its bod…