POJ 1491

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void swap(int &a, int &b)
{
	int c = a;
	a = b;
	b = c;
}

int gcd(int a, int b)
{
	if(a < b) swap(a, b);
	if(a % b == 0)
		return b;
	else return gcd(b, a%b);
}



int main()
{
	int n;

	int i, j, count;
	
	scanf("%d", &n);

	while( n !=0)
	{
		count = 0; 

		int * data =(int *) malloc(n * sizeof(int));

		for(i = 0; i < n; i++)
		{
			scanf("%d",&data[i]);
		}
		
		for(i = 0; i < n; i++)
			for(j = i+1; j < n; j++)
			{
				if(gcd(data[i], data[j]) == 1) count++;
			}

		if(count == 0) printf("No estimate for this data set.\n");
		else
			printf("%.6f\n",sqrt((double)3 * n*(n-1) /count));

		scanf("%d", &n);

	}
	return 0;
}

你可能感兴趣的:(C++,c,C#,J#)