POJ 3904】的更多相关文章

B - Sky Code Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3904 Description Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraft. Tha…
POJ 3904 题意: 从n个数中选择4个数使他们的GCD = 1,求总共有多少种方法 Sample Input 4 2 3 4 5 4 2 4 6 8 7 2 3 4 5 7 6 8 Sample Output 1 0 34 思路:先求出选择四个数所有的情况,C(4,n) = n * (n-1) * (n-2) * (n-3),然后减去GCD为2,GCD为3......:在这过程中我们会把GCD = 6减去两次,所以需要加上.刚好满足莫比乌斯函数 函数:合数为0 ,质数数目为奇  -1,质数…
http://poj.org/problem?id=3904   题意:给一些数,求在这些数中找出四个数互质的方案数.   莫比乌斯反演的式子有两种形式http://blog.csdn.net/outer_form/article/details/50588307 这里用的是第二种形式. 求出四个数的公约数为x的倍数的方案数,即可得到,四个数的公约数为x的方案数. 这里x为1. 代码 #include<cstdio> #include<cstring> #include<io…
[题目链接] http://poj.org/problem?id=3904 [算法] 问题可以转化为求总的四元组个数 - 公约数不为1的四元组个数 总的四元组个数为C(n,4),公约数不为1的四元组个数可以用容斥原理求 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cma…
题目链接:http://poj.org/problem?id=3904 题目大意: 给出一个数列,询问从中取4个元素满足最大公约数为1的方案数 题解: 很显然,ans=总的方案数-最大公约数大于1的4个元素的组合的方案数   =总的方案数-存在公约数大于1的4个元素的组合的方案数 考虑后者如何计算 容斥一下 后者=含有一个质因子(不仅仅是一个,应该是至少一个,后面的同理)的元素的个数取4的方案数-含有两个质因子的元素的个数取4的方案数+含有三个质因子的元素的个数取4的方案数... 朴素做法是枚举…
第一道莫比乌斯反演的题. 建议参看http://www.isnowfy.com/mobius-inversion/ 摘其中部分 证明的话感觉写起来会比较诡异,大家意会吧说一下这个经典题目:令R(M,N)=1≤x≤M,1≤y≤N中 gcd(x,y)=1 的个数我们说G(z)表示gcd(x,y)是z的倍数的个数(以后都省略1≤x≤M,1≤y≤N的前提),换句话说z|gcd(x,y)的个数,那么很显然G(z)=⌊M/z⌋∗⌊N/z⌋,令F(z)表示gcd(x,y)=z的个数, 所以G(z)=∑(F(z…
题意:给定n个数ai, ai <= 10000, n <= 10000, 从中选出4个数要求gcd为1,这样的集合有多少个? 分析:首先总共集合nCr(n, 4) = n*(n-1)*(n-2)*(n-3)/24个,那么需要减掉gcd >=2 的集合.先减掉gcd为各个素数的方案数目,然后再由这些素数组成一些因子,考虑gcd为这些因子的情况.最后总结起来就是,素数个数为奇数时,减去:素数个数为偶数时,加上.具体实现的时候只要对每个ai分解质因数,然后单独考虑他的素因子能组成哪些数,这样再…
Sky Code Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1750   Accepted: 545 Description Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraft. That is why he is preparing to ste…
Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraft. That is why he is preparing to steal the spacecraft of Petru. There is only one problem – Petru has locked the spacecraft with a sophisti…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…