poj1491

简单题

View Code
#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



#define maxn 55



int n;

int f[maxn];



int gcd(int a, int b)

{

    if (b > 0)

        return gcd(b, a % b);

    return a;

}



void input()

{

    for (int i = 0; i < n; i++)

        scanf("%d", &f[i]);

}



void work()

{

    int numerator = 0;

    for (int i = 0; i < n; i++)

        for (int j = i + 1; j < n; j++)

            if (gcd(f[i], f[j]) == 1)

                numerator++;

    if (numerator == 0)

    {

        printf("No estimate for this data set.\n");

        return;

    }

    printf("%.6f\n", sqrt(n * (n - 1) * 3.0 / numerator));

}



int main()

{

//    freopen("t.txt", "r", stdin);

    while (scanf("%d", &n), n)

    {

        input();

        work();

    }

    return 0;

}

 

你可能感兴趣的:(poj)