HDU 5656 CA Loves GCD (容斥)】的更多相关文章

题意:给定一个数组,每次他会从中选出若干个(至少一个数),求出所有数的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…
CA Loves GCD  Accepts: 64  Submissions: 535  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 262144/262144 K (Java/Others) 问题描述 CA喜欢是一个热爱党和人民的优秀同♂志,所以他也非常喜欢GCD(请在输入法中输入GCD得到CA喜欢GCD的原因). 现在他有N个不同的数,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去. 为了使自己不会无聊,CA…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5656 bc:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=683&pid=1002 CA Loves GCD Accepts: 64    Submissions: 535 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/2…
CA Loves GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 Description CA is a fine comrade who loves the party and people; inevitably she loves GCD (greatest common divisor) too. Now, there are N different numbers. Each time, CA will select s…
CA Loves GCD 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/B Description CA is a fine comrade who loves the party and people; inevitably she loves GCD (greatest common divisor) too. Now, there are different numbers. Each time, CA will se…
CA Loves GCD Accepts: 135 Submissions: 586 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 CA喜欢是一个热爱党和人民的优秀同♂志,所以他也非常喜欢GCD(请在输入法中输入GCD得到CA喜欢GCD的原因). 现在他有N个不同的数,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去. 为了使自己不会无聊,CA会把每…
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1707    Accepted Submission(s): 543 Problem Description CA is a fine comrade who loves the party and people; inevitably she loves G…
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 882    Accepted Submission(s): 305 Problem Description CA is a fine comrade who loves the party and people; inevitably she loves GC…
题目的意思就是: n个数,求n个数所有子集的最大公约数之和. 第一种方法: 枚举子集,求每一种子集的gcd之和,n=1000,复杂度O(2^n). 谁去用? 所以只能优化! 题目中有很重要的一句话! We guarantee that all numbers in the test are in the range [1,1000]. 1 1 这句话对解题有什么帮助? 子集的种数有2^n种,但是,无论有多少种子集,它们的最大公约数一定在1-1000之间. 所以,我们只需要统计1-1000的最大公…
CA Loves GCD  Accepts: 135  Submissions: 586  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 262144/262144 K (Java/Others) 问题描述 CA喜欢是一个热爱党和人民的优秀同♂志,所以他也非常喜欢GCD(请在输入法中输入GCD得到CA喜欢GCD的原因). 现在他有N个不同的数,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去. 为了使自己不会无聊,C…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 CA Loves Stick Accepts: 381   Submissions: 3204 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others) 问题描述 CA喜欢玩木棍. 有一天他获得了四根木棍,他想知道用这些木棍能不能拼成一个四边形.(四边形定义:https://e…
题目链接: CA Loves GCD Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others) Problem Description   CA is a fine comrade who loves the party and people; inevitably she loves GCD (greatest common divisor) too. Now, there ar…
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…
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),直接累加肯定…
题目链接 求 $ 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 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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5768 给你n个同余方程组,然后给你l,r,问你l,r中有多少数%7=0且%ai != bi. 比较明显的中国剩余定理+容斥,容斥的时候每次要加上个(%7=0)这一组. 中间会爆longlong,所以在其中加上个快速乘法(类似快速幂).因为普通的a*b是直接a个b相加,很可能会爆.但是你可以将b拆分为二进制来加a,这样又快又可以防爆. //#pragma comment(linker, "/STACK…
题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd(a_1,a_2,a_3…a_n)=d$,显然每个$a_i$的倍数都满足,有$\frac{a_i}{d}$种方案 那么一个d对答案的贡献为\[\prod_{i=1}^{min(a)}{\lfloor\frac{a_i}{d}\rfloor}    \] 但是所有的d计入会有重复情况,考虑容斥,对d进行素数分…
Problem Description CA is a fine comrade who loves the party and people; inevitably she loves GCD (greatest common divisor) too. Now, there are N different numbers. Each time, CA will select several numbers (at least one), and find the GCD of these n…
题意: 析:首先很容易可以看出来使用FFT是能够做的,但是时间上一定会TLE的,可以使用公式化简,最后能够化简到最简单的模式. 其实考虑使用组合数学,如果这个 xi 没有限制,那么就是求 x1 + x2 + x3 +... xm = k,有多少非零解,隔板法很容易得到答案 C(k+m-1, m-1),但是有限制怎么办,使用容斥,考虑有一个变量超过 n-1,两个变量超过 n-1,等等,根据集合论,很容易知道偶加,奇减... 代码如下: #pragma comment(linker, "/STACK…
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不会 就自己写了个容斥搞一下(才能维持现在的生活) //别人的题解https://blog.csdn.net/luyehao1/article/details/81672837 #include <iostream> #include <cstdio> #include <cstr…
题意:有一块(1,1)到(m,n)的地,从(0,0)看能看到几块(如果两块地到看的地方三点一线,后面的地都看不到). 思路:一开始是想不到容斥...后来发现被遮住的地都有一个特点,若(a,b)有gcd(a,b)!= 1,那么就会被遮住.因为斜率k一样,后面的点会被遮住,如果有gcd,那么除一下就会变成gcd = 1的那个点的斜率了.所以问题转化为求gcd不为1有几个点,固定一个点,然后容斥. #include<set> #include<map> #include<queue…
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6869    Accepted Submission(s): 2710 Problem Description Given a number N, you are asked to count the number of integers between A and B…
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…
题意:给你n个数[4,10000],问在其中任意选四个其GCD值为1的情况有几种. 思路:GCD为1的情况很简单 即各个数没有相同的质因数,所以求所有出现过的质因数次数再容斥一下-- 很可惜是错的,因为完全有可能某四个数有两个公共质因数,所以还是使用普通的因子分解 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <utili…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 bzoj 4036 的简单版,Min-Max 容斥即可. 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef double db; ,xm=(<<)+; int n,bin[xn]; db p[xn],mn[xm]; ; ),s>…
TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3401    Accepted Submission(s): 1268 Problem Description You are given an array A , and Zhu wants to know there are how many different…
CA Loves Stick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 981    Accepted Submission(s): 332 Problem Description CA loves to play with sticks.One day he receives four pieces of sticks, he…
CA Loves Palindromic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 301    Accepted Submission(s): 131 Problem Description CA loves strings, especially loves the palindrome strings. One day…
Lucky7 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) 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 d…