题意:给出N个数,求其中互质的数的个数m,然后用公式求pi
6/pi^2=m/(N*(n-1)/2)
#include <stdio.h>
#include <math.h>
#include <string.h>
int number[55];
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int N;
while(scanf("%d",&N)!=EOF&&N)
{
int num=0;
memset(number,0,sizeof(number));
for(int i=0;i<N;i++)
scanf("%d",&number[i]);
for(int i=0;i<N;i++)
{
for(int j=i+1;j<N;j++)
{
int t=number[i]>number[j]?gcd(number[i],number[j]):gcd(number[j],number[i]);
if(t==1)
num++;
}
}
N=N*(N-1)/2;
if(num==0)
printf("No estimate for this data set.");
else
{
double pi=sqrt(6*N*1.0/num);
printf("%.6lf",pi);
}
printf("\n");
}
return 0;
}