Triple

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 1365    Accepted Submission(s): 549

Problem Description
Given many different integers, find out the number of triples (a, b, c) which satisfy a, b, c are co-primed each other or are not co-primed each other. In a triple, (a, b, c) and (b, a, c) are considered as same triple.
 
Input
The first line contains a single integer T (T <= 15), indicating the number of test cases. In each case, the first line contains one integer n (3 <= n <= 800), second line contains n different integers d (2 <= d < 105) separated with space.
 
Output
For each test case, output an integer in one line, indicating the number of triples.
 
Sample Input
1 6 2 3 5 7 11 13
 
Sample Output
20
 
Source
 
给你n个数,对于其中的任意n个数,a,b,c 要么两两互斥,要么a,b,c两两不互斥......
要你求出满足这一条件的组合数。
分析:
    对于任意的三个数,a,b,c 我们知道有这些情况,0对互斥(即两两都不互斥),1对互斥,两对互斥,三对互斥(即两两互斥)。
  代码:

 #include<cstdio>
#include<cstring>
using namespace std;
const int maxn=;
int item[maxn];
int gcd(int a,int b)
{
if(b==)return a;
return gcd(b,a%b);
}
int main()
{
int cas,n;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",item+i);
int ans=;
for(int i=;i<n;i++)
{
int numa=,numb=;
for(int j=;j<n;j++)
{
if(i!=j)
{
if(gcd(item[i],item[j])==)numa++;
else numb++;
}
}
ans+=numa*numb;
}
printf("%d\n",(n*(n-)*(n-)/)-ans/);
}
return ;
}

hdu 3908 Triple(组合计数、容斥原理)的更多相关文章

  1. 集训队8月9日(组合计数+容斥原理+Mobius函数)

    刷题数:4 今天看了组合计数+容斥原理+Mobius函数,算法竞赛进阶指南169~179页 组合计数 https://www.cnblogs.com/2462478392Lee/p/11328938. ...

  2. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

  3. bzoj2839 集合计数 组合计数 容斥原理|题解

    集合计数 题目描述 一个有N个元素的集合有2^N个不同子集(包含空集),现在要在这2^N个集合中取出若干集合(至少一个),使得它们的交集的元素个数为K,求取法的方案数,答案模1000000007.(是 ...

  4. UVa 11806 - Cheerleaders (组合计数+容斥原理)

    <训练指南>p.108 #include <cstdio> #include <cstring> #include <cstdlib> using na ...

  5. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [分治FFT 组合计数 | 多项式求逆]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

  6. [总结]数论和组合计数类数学相关(定理&证明&板子)

    0 写在前面 0.0 前言 由于我太菜了,导致一些东西一学就忘,特开此文来记录下最让我头痛的数学相关问题. 一些引用的文字都注释了原文链接,若侵犯了您的权益,敬请告知:若文章中出现错误,也烦请告知. ...

  7. HDU4609 FFT+组合计数

    HDU4609 FFT+组合计数 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意: 找出n根木棍中取出三根木棍可以组成三角形的概率 题解: ...

  8. ACM组合计数入门

    1 排列组合 1.1 排列 \[A_n^m=n(n-1)(n-2)\cdots(n-m+1)=\frac{n!}{(n-m)!} \] 定义:从 n 个中选择 m 个组成有序数列,其中不同数列的数量. ...

  9. bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)

    黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...

随机推荐

  1. Ghostscript命令实践

    一. 将单张PDF文件igs.pdf转化为tiff文件. . gs -sDEVICE=tiffg4 -sOutputFile=igs.tiff -dMaxStripSize= igs.pdf -dAd ...

  2. Django 过滤器 实例

    实例1 safe让Html标签以及一些特殊符号(如<)生效,下面以例子说明: # value = '<b>CPT</b>' # 那么输出的时候,CPT就是加粗的,如果不加 ...

  3. 对Spring <context:annotation-config/>的理解

    在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是向 Spring 容器注册 AutowiredAnn ...

  4. SQL Server 小技巧【2】

    --1.不要使用×来查询所有字段 SELECT * FROM DBO.tb1 --改为 SELECT FName,PWD,CreateDate FROM DBO.tb1 (NOLOCK) --2.查询 ...

  5. CUBRID学习笔记 41 sql语法之groupby 等

    cubrid的中sql查询语法groupby GROUP BY ... HAVING Clause 按dept_no分组 SELECT dept_no, avg(sales_amount) FROM ...

  6. So easy Webservice 6.使用EndPoint发布webservice服务

    创建第一个Web服务: @WebService // 添加了此注解,代表是一个WebService public class HelloWorld { // 非 static final privat ...

  7. Comware 架构理解

    网络操作系统 首先什么是网络操作系统: 一种说法是:运行在路由器,网络交换机,防火墙上的特别的操作系统 另一种说法是:部署在局域网或者私有网络,允许网络中的多个计算机共享文件和打印机,因为现在的单机系 ...

  8. 拓扑排序--UVa10305

    题目 Output: standard output Time Limit: 1 second Memory Limit: 32 MB John has n tasks to do. Unfortun ...

  9. shift移动变量

    1.移动变量 脚本 sh05.sh #!/bin/bash # Program # Program shows the effect of shift function # History: # // ...

  10. Android_使用 OpenVPN

    1. 需要 root http://www.doc88.com/p-847633362717.html http://bbs.gfan.com/android-3679297-1-1.html 需要 ...