POJ 1491 Pi G++

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//抄博友程序 gcd题 
int a[108];
int gcd(int x,int y)//x大 y小 
{
	int t;
	if(x<y)
	{
		t=x;
		x=y;
		y=t;
	}
	if(y==1)
	{
		return 1;
	}else if(y==0)
	{
		return x;
	} 
	return gcd(y,x%y);
}
int main()
{
	/*
	while(1)
	{
		int a,b;
		cin>>a>>b;
		cout<<gcd(a,b)<<endl;		
	}*/
	while(1)
	{
		int n;
		cin>>n;
		if(n==0)
		{
			break;
		}
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		int num=0;
		for(int i=0;i<n-1;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(gcd(a[i],a[j])==1)
				{
					num++;
				}
			}
		}
		if(num==0)
		{
			cout<<"No estimate for this data set."<<endl;
		}else
		{
			cout<<fixed<<setprecision(6)<<sqrt(3.0*n*(n-1)/(double)num)<<endl;
		}
	} 
	return 0;
}
发布了1118 篇原创文章 · 获赞 9 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/woniupengpeng/article/details/104098616
pi
g++