标签:des style blog http color io os ar java
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 1365 Accepted Submission(s): 549
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int maxn=100005; 5 int item[maxn]; 6 int gcd(int a,int b) 7 { 8 if(b==0)return a; 9 return gcd(b,a%b); 10 } 11 int main() 12 { 13 int cas,n; 14 scanf("%d",&cas); 15 while(cas--) 16 { 17 scanf("%d",&n); 18 for(int i=0;i<n;i++) 19 scanf("%d",item+i); 20 int ans=0; 21 for(int i=0;i<n;i++) 22 { 23 int numa=0,numb=0; 24 for(int j=0;j<n;j++) 25 { 26 if(i!=j) 27 { 28 if(gcd(item[i],item[j])==1)numa++; 29 else numb++; 30 } 31 } 32 ans+=numa*numb; 33 } 34 printf("%d\n",(n*(n-1)*(n-2)/6)-ans/2); 35 } 36 return 0; 37 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/gongxijun/p/4049046.html