LightOJ 1161 - Extreme GCD 容斥】的更多相关文章

题意:给你n个数[4,10000],问在其中任意选四个其GCD值为1的情况有几种. 思路:GCD为1的情况很简单 即各个数没有相同的质因数,所以求所有出现过的质因数次数再容斥一下-- 很可惜是错的,因为完全有可能某四个数有两个公共质因数,所以还是使用普通的因子分解 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <utili…
1161 - Extreme GCD    PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB All of you know that GCD means the greatest common divisor. So, you must have thought that this problem requires finding some sort of GCD. Don't worry, y…
GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 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) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be…
题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, b/k] $ 内 \(gcd(x, y) = 1\) 的(x, y)的对数. 假设a < b, 那么[1, a/k]这部分可以用欧拉函数算. 设 \(i\in (a/k, b/k]\), (a/k, b/k]这部分可以用容斥算, 用a/k减去[1, a/k]里面和i不互质的数的个数. 具体看代码.…
题意:给定一个数组,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去,为了使自己不会无聊,会把每种不同的选法都选一遍,想知道他得到的所有GCD的和是多少. 析:枚举gcd,然后求每个gcd产生的个数,这里要使用容斥定理,f[i]表示的是 gcd 是 i 的个数,g[i] 表示的是 gcd 是 i 倍数的,f[i] = g[i] - f[j] (i|j). 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&qu…
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给定一个数组,我们定义一个新的数组b满足bi<ai 求满足gcd(b1,b2....bn)>=2的数组b的个数 题解:利用容斥定理.我们先定义一个集合f(x)表示gcd(b1,b2...bn)为x倍数的个数(x为质数),我们在定义一个数mi为数组中的最小值,那么集合{f(2)Uf(3)....f(n)}就是我们想要的答案.f(x)=(a1/x)*(a2/x)*.....(ai/x),直接累加肯定…
ans = sigma_x(sigma_y(gcd(x,y) * 2 - 1)),1<=x<=n,1<=y<=m 枚举x,y,O(nmlogn),超时 换个角度,枚举d = gcd(x,y) d对ans的贡献为2*d-1 若有n个(x,y)使得gcd(x,y) = d,则贡献为n * (2 * d - 1) f(d) 表示gcd(x,y) = d 的(x,y)个数 ans = sigma(f[d] * (2 * d - 1)),1 <= d <= min(n,m) 那么…
GCD Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 2 Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b…
题意:求区间1<=i<=b与区间1<=j<=d之间满足gcd(i,j) = k 的数对 (i,j) 个数.(i,j)与(j,i) 算一个. 分析:gcd(i,j)=k可以转化为gcd(i/k,j/k)=1.枚举每个1<=i<=b/k 的 i,用容斥原理统计区间[1,d]中与其互素的个数.需要预处理筛出2~1e5中每个数的质因子. *注意当k=0时,数对不存在. #include<bits/stdc++.h> using namespace std; type…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17385    Accepted Submission(s): 6699 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…