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…
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包括零),求小于N的 正整数(1~N-1)中,能被M个整数的集合中随意一个元素整除的正整数个数. 比如N = 12.M = {2,3},在1~N-1中,能被2整除的数为{2,4,6.8.10},能被3整除的数为 {3.6,9}.则所求集合为{2,3,4.6,8,9,10},共7个,则答案为7. 思路:…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3315    Accepted Submission(s): 937 Problem Description   Now you get a number N, and a M-integers set, you shoul…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3556 How Many Sets I Time Limit: 2 Seconds      Memory Limit: 65536 KB Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4141    Accepted Submission(s): 1441 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)…
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 935    Accepted Submission(s): 339 Problem Description Given a number N, you are asked to count the number of integers between A and B in…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7529    Accepted Submission(s): 2773 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…
Description As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, eats as much of it as it can (or wants), then stretches out to its full length to reach a new leaf with its front end, and finally "hops" to it by c…
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 body and sent it back to the shore. It is said that ?? used to surrounded by 7…
Problem Description Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than…
Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1951    Accepted Submission(s): 792 Problem Description There are many trees forming a m * n grid, the grid starts from (1,1). Farm…
题目连接:hdu_5213_Lucky 题意:给你n个数,一个K,m个询问,每个询问有l1,r1,l2,r2两个区间,让你选取两个数x,y,x,y的位置为xi,yi,满足l1<=xi<=r1,l2<=y2<=r2,使得x+y=K: 题解:首先,这题没有修改操作,即可以离线,离线区间问题就要想到莫队算法,然后看状态怎么搞,因为要求的答案满足区间的可加性,我们令f(l,r)表示 l到r这个区间满足条件的ans,令F(l1,r1,l2,r2)为在这两个区间内选取的数满足条件的ans,则根…
题意:给定区间和n,求区间中与n互素的数的个数, . 思路:利用容斥定理求得先求得区间与n互素的数的个数,设表示区间中与n互素的数的个数, 那么区间中与n互素的数的个数等于.详细分析见求指定区间内与n互素的数的个数 容斥原理 AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <bitset> #include <algorithm> #include <cs…
2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MB Submit: 7732  Solved: 3750 [Submit][Status][Discuss] Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 100%的数据满足:1≤n≤50000,1≤a≤b≤50000,1≤c≤d≤50000…
题目 一个有 \(N\) 个 元素的集合有 \(2^N\) 个不同子集(包含空集), 现在要在这 \(2^N\) 个集合中取出若干集合(至少一个), 使得它们的交集的元素个数为 \(K\) ,求取法的方案数,答案模 \(1000000007\) . \((1 \le N \le 10^6, 0 \le K \le N)\) 题解 又是一道 裸的 广义容斥定理 还没这道题难qwq 广义容斥定理 (二项式反演) : \[\displaystyle b_k = \sum_{i=k}^n \binom…
1284 2 3 5 7的倍数 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题   给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N = 10,只有1不是2 3 5 7的倍数. Input 输入1个数N(1 <= N <= 10^18). Output 输出不是2 3 5 7的倍数的数共有多少. Input示例 10 Output示例 1经典的容斥定理,公式 |AUBUC|=|A|+|B|+|C|-|A^B|-|A^C|-|B^C|+|A…
1003 染色         Time Limit: 1sec    Memory Limit:256MB Description 今天离散数学课学了有关树的知识,god_v是个喜欢画画的人,所以他喜欢对于一棵树上色,且相邻节点不能染相同颜色,他有k种颜色,他希望他染色完后,这棵树上每种颜色都有,他想请教你有多少种染色方案?由于方案数过大,输出对1e9+7取模的结果. Input 第一行 n,k表示树的节点和颜色数量(1<=k<=n<=100000) 第二行 n-1个数字,第i个数字表…
[HDU4135]Co-prime 题意 给出三个整数N,A,B.问在区间[A,B]内,与N互质的数的个数.其中N<=10^9,A,B<=10^15. 分析 容斥定理的模板题.可以通过容斥定理求出[1,n]与x互质的数的个数.方法是先将x进行质因子分解,然后对于每个质因子pi,[1,n]内可以被pi整除的数目为n/pi.可以通过容斥定理解决逆命题,既[1,n]与x不互质的数目.n/p1+n/p2+n/p3-n/p1p2-n/p1p3-n/p2p3+n/p1p2p3.既奇数是加,偶数是减.具体的…
n*m的矩形 k个人 第一行,最后一行,第一列,最后一列都至少站有一个人 小水题 正着做不好做,要反着想,那就容斥定理,ABCD四种情况分别是那四个行列分别没有人. #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; ; ; ][]; int main() { //freopen("a.in","…
20180604 给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N = 10,只有1不是2 3 5 7的倍数. Input 输入1个数N(1 <= N <= 10^18). Output 输出不是2 3 5 7的倍数的数共有多少. Sample Input 10 Sample Output 1 思路: ⒈如果对数学不是很了解,这道题可以按照常规思路来,只是分得不完,毕竟数据太大会爆掉.(20道测试过了7道) #include<cstdio> #include&…
描述 给一个整数N,请你求出以N为分母的最简(既约)真分数中第K小的是多少? 输入 两个整数N个K. 对于30%的数据,1 <= N <= 1000000 对于100%的数据,1 <= N <= 10000000000 且 1 <= K <= φ(N).其中φ(N)是欧拉函数,也即1~N中与N互质的数的个数. 输出 一个整数表示答案的分子 样例输入 100 10 样例输出 23 思路: 显然和欧拉函数关系不大...开始思路已经很接近了.分解质因子,然后二分1到Mid中与…
传送门 题意 给出n个数和幸运数k,m次询问,每次询问[l1,r1]和[l2,r2]有多少对数满足x+y=k,x∈[l1,r1],y∈[l2,r2] 分析 看到m只有3e4,可以考虑\(m\sqrt{n}\)的莫队算法,具体讲解.首先设f(l,r)表示从l到r满足x+y=k的对数,那么由容斥定理得到,\[f(l1,r1,l2,r2)=f(l1,r2)-f(l1,l2-1)-f(r1+1,r2)+f(r1+1,l2-1)\],那么就可以结合莫队算法离线求出询问结果,具体见代码 trick 代码 #…
题目链接:https://cn.vjudge.net/problem/UVA-11806 题意 在一个mn的矩形网格里放k个石子,问有多少方法. 每个格子只能放一个石头,每个石头都要放,且第一行.最后一行.第一列和最后一列都有石子. 思路 设A为第一行格子.B为最后一行.C为第一列.D为最后一列. 很明显发现ABCD这个集合包含了重复元素,那么按照容斥定理可解. 注意: 1000007 不是素数,不能递推算逆元,因为mod%i==0 不要用乘法递推式算C,要用加法 容斥的技巧,用cont计数总方…
Luogu-P1450 [HAOI2008]硬币购物-完全背包+容斥定理 [Problem Description] 略 [Solution] 上述题目等价于:有\(4\)种物品,每种物品有\(d_i\)个,且每种物品的体积为\(c_i\),问有多少种方法装满容量为\(s\)的背包?可以很容易想到跑多重背包即可,但是发现复杂度为\(O(4V\cdot n)\).不可行. 题目要求的东西也等价于求以下等式有多少组满足条件的解: \[ c_1\cdot x_1+c_2\cdot x_2+c_3\cd…
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 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): 6001    Accepted Submission(s): 1722 Problem Description   Now you get a number N, and a M-integers set, you shou…
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Let's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest…
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…
题意:给定一个数 n,和一个集合 m,问你小于的 n的所有正数能整除 m的任意一个的数目. 析:简单容斥,就是 1 个数的倍数 - 2个数的最小公倍数 + 3个数的最小公倍数 + ...(-1)^(n+1) * n个数的最小公倍数. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdl…