**题意:**给你n个数[4,10000],问在其中任意选四个其GCD值为1的情况有几种。
**思路:**GCD为1的情况很简单 即各个数没有相同的质因数,所以求所有出现过的质因数次数再容斥一下……
很可惜是错的,因为完全有可能某四个数有两个公共质因数,所以还是使用普通的因子分解

#include <stdio.h>

#include <iostream>

#include <string.h>

#include <algorithm>

#include <utility>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <stack>

#include <queue>

#define LL long long

#define MMF(x) memset((x),0,sizeof(x))

#define MMI(x) memset((x), INF, sizeof(x))

using namespace std;



const int INF = 0x3f3f3f3f;

const int N = 1e4+20;



LL mar[N];

LL ans[N];

LL C4(LL n)//组合数4的函数

{

return n*(n-1)*(n-2)*(n-3)/24;

}

void rec(int n)//分解因子 并记录个数

{

for(int i = 1; i*i <= n; i++)

{

if(n % i == 0)

{

mar[i]++;

if(n / i != i)

mar[n/i]++;

}

}

}



int main()

{

// prime();

int T;

int cnt = 0;

cin >> T;

while(T--)

{

int n;

scanf("%d", &n);

MMF(mar);

for(int i = 0; i < n; i++)

{

int t;

scanf("%d", &t);

rec(t);

}

for (int i = 10000; i >= 1; --i) {

ans[i] = C4(mar[i]);

for (int j = 2 * i; j <= 10000; j += i)

{

ans[i] -= ans[j];

}

}

printf("Case %d: %lld\n", ++cnt, ans[1]);

}

return 0;

}

//刚开始想找质因数排列组合 WA后一想 可能存在这种情况:某4个数的 相同质因数 有两种,这样后的容斥情况重复了

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

  1. 1161 - Extreme GCD

    1161 - Extreme GCD    PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB All ...

  2. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  3. hdu 1695 GCD 容斥+欧拉函数

    题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, ...

  4. HDU 5656 CA Loves GCD (容斥)

    题意:给定一个数组,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去,为了使自己不会无聊,会把每种不同的选法都选一遍,想知道他得到的所有GCD的和是多少. 析:枚举gcd,然后求每个 ...

  5. hdu 6053 trick gcd 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给定一个数组,我们定义一个新的数组b满足bi<ai 求满足gcd(b1,b2....bn)&g ...

  6. bzoj2005 能量采集 gcd 容斥

    ans = sigma_x(sigma_y(gcd(x,y) * 2 - 1)),1<=x<=n,1<=y<=m 枚举x,y,O(nmlogn),超时 换个角度,枚举d = g ...

  7. 【hdu-2588】GCD(容斥定理+欧拉函数+GCD()原理)

    GCD Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  8. HDU - 1695 GCD (容斥+枚举)

    题意:求区间1<=i<=b与区间1<=j<=d之间满足gcd(i,j) = k 的数对 (i,j) 个数.(i,j)与(j,i) 算一个. 分析:gcd(i,j)=k可以转化为 ...

  9. GCD HDU - 1695 (欧拉 + 容斥)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. Python的top-level脚本为什么在磁盘上没有对应的字节码?

    在Python中,如果你使用python script.py这样的方式运行Python脚本,那么script.py就被称为top-level脚本.对于Python来说,这个脚本的字节码是不会写入到磁盘 ...

  2. Java学习个人备忘录之内部类

    内部类: 将一个类定义在另一个类的里面,对里面那个类就称为内部类. class Outer { private int num = 3; class Inner //它想访问Outer中的num, 如 ...

  3. Java 类和Static关键字

    类的定义 类的命名.首字母大写 大括号后面没有分号 成员变量 Java会自动初始化成员变量但是不会自动初始化局部变量: 可以在定义成员变量是直接初始化,成员变量的作用范围在整个类体 对象的创建和引用的 ...

  4. iOS- <项目笔记> UIApplication常见属性与方法总结

    UIApplication 1.简介 1> 整个应用程序的象征,一个应用程序就一个UIApplication对象,使用了单例设计模式 2> 通过[UIApplication sharedA ...

  5. C# 正则表达式 最全的验证类

    ///<summary> ///验证输入的数据是不是正整数 ///</summary> ///<param name="str">传入字符串&l ...

  6. 原生js 自定义confirm

    本文参考博客园另一篇文章:https://www.cnblogs.com/hzj680539/p/5374052.html,在此感谢. 在实际开发当中,考虑到原生js组件,包括alert.confir ...

  7. java 基本--数据类型转换--001

    小可转大,大转小可能会损失精度(编译出错,需要强制转换)A: byte,short,char -> int -> long -> float ->doubleB: byte,s ...

  8. datepicker约束开始时间和结束时间

    datepicker约束开始时间和结束时间作用就是:选择要搜索的日期范围. <!DOCTYPE html> <html lang="en"> <hea ...

  9. BZOJ2428:[HAOI2006]均分数据——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=2428 https://www.luogu.org/problemnew/show/P2503 已知 ...

  10. BZOJ1877:[SDOI2009]晨跑——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1877 https://www.luogu.org/problemnew/show/P2153 Ela ...