pku1491.cpp

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 54 行

CPP
54
字号
#include <stdio.h>
#include <math.h>
#define size 100
int a[size];
int N;
int gcd(int x, int y)
{
	int t;
	while (y != 0)
	{
		t = x % y;
		x = y;
		y = t;
	}
	if (x == 1)
	{
		return 1;
	}
	return 0;
}

int main()
{
	double all, cnt, ans;
	int i, j;
	while (scanf("%d", &N) != -1 && N)
	{
		for (i = 0; i < N; i++)
		{
			scanf("%d", &a[i]);
		}
		all = N * (N - 1) / 2;
		cnt = 0;
		for (i = 0; i < N; i++)
		{
			for (j = i + 1; j < N; j++)
			{
				cnt += gcd(a[i], a[j]);
			}
		}
		if (cnt == 0)
		{
			printf("No estimate for this data set.\n");
		}
		else
		{
			ans = sqrt(all * 6 / cnt);
			printf("%.6lf\n", ans);
		}
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?