hdu 3908 Triple
来源:互联网 发布:golang mongodb in 编辑:程序博客网 时间:2024/05/21 17:31
Triple
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 205 Accepted Submission(s): 84
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.
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
162 3 5 7 11 13
Sample Output
20
Source
2011 Multi-University Training Contest 7 - Host by ECNU
题解:这题比赛时卡了很久,后然才发现要用逆向思维,总数减去不满足的情况。
#include <iostream>using namespace std;int a[805];int n,ans;int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}int main(){int i,j,T,x,y,s;scanf("%d",&T);while(T--){scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);ans=n*(n-1)*(n-2)/6;s=0;for(i=1;i<=n;i++){x=y=0;for(j=1;j<=n;j++){if(i==j)continue;if(gcd(a[i],a[j])==1)x++;elsey++;}s+=x*y;}printf("%d\n",ans-s/2);}return 0;}
- hdu 3908 Triple
- HDU 3908 Triple
- hdu 3908 Triple
- 【组合】HDU 3908 Triple
- HDU 3908 Triple (逆向思维)
- Triple HDU
- HDU/HDOJ 3908 Triple 多校联合7
- HDU 5517 Triple (线段树)
- triple
- Triple
- hdu 5517 Triple(二维树状数组)
- hdu 5517 Triple 二维树状数组
- HDOJ 题目3908Triple(数学)
- HDU 5517 (ACM 2015 沈阳) Triple [树状数组]
- Triple Buffering
- hdu517 Triple
- BZOJ3771: Triple
- BZOJ3771 Triple
- 1
- android-addSpinner
- PHP XML Expat 解析器
- Oracle_AWR_报告分析实例讲解
- 在RHEL5下实现RAID5磁盘阵列
- hdu 3908 Triple
- ClassLoader原理
- PHP XML DOM
- PhysX物理引擎入门
- Boost学习系列5-字符串处理-(上)
- PHP SimpleXML
- 性能测试指标
- AJAX 简介
- java classLoader 体系结构