**题意:**给你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. [leetcode-744-Find Smallest Letter Greater Than Target]

    Given a list of sorted characters letters containing only lowercase letters, and given a target lett ...

  2. POJ 2069 Super Star(计算几何の最小球包含+模拟退火)

    Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...

  3. Alpha发布——视频展示

    一.视频链接 http://v.youku.com/v_show/id_XMzEyODQzNzQ2MA==.html 二.视频文案说明 你是不是还在为软工作业奋笔疾书? 你是不是无法及时查看最新博客信 ...

  4. Pipeline组Alpha版本发布说明

    Pipeline组Alpha版本发布说明 项目名称 Pipeline 项目版本 Alpha版本 负责人 北京航空航天大学计算机学院 ILoveSE 联系方式 http://www.cnblogs.co ...

  5. SOA架构的理解

    实践论认为:从实践提升到理论,再由理论指导实践,由此向前发展.目前SOA的发展的情况………… 通过不少实践,SOA的模型己经被公认为标准规范,目前是正需要进一步总结上升到理论的时候了. SOA架构的演 ...

  6. 后端设置cookie写不到前端页面

    javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("id",session.getId()); co ...

  7. ACM 第十五天

    计算几何基础 练习题 C - Wasted Time Mr. Scrooge, a very busy man, decided to count the time he wastes on all ...

  8. iOS-修改导航栏文字字体和颜色

    //修改导航栏文字字体和颜色 nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[RGBColor co ...

  9. 【alpha】Scrum站立会议第1次····10.16

    小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app 1.任务进度 成员 已完成 当日要完成 李权 搭建好Android Studio环境 数据库设计 于淼 搭建好Andro ...

  10. Jmeter系列-webdriver代码范例

    范例 WDS.sampleResult.sampleStart() try{ //打开博客首页 WDS.browser.get('http://xqtesting.blog.51cto.com') / ...