Uva 412 Solution

#include<bits/stdc++.h>
#define ll long int
using namespace std;
int gcd(int a, int b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}

int main()
{
    ll n, i, j;
    while(cin >> n && n > 0)
    {
        int a[n];
        int b = 0, c = 0;
        for(i=0;i<n;i++)
            cin >> a[i];
        for(i=0;i<n-1;i++)
        {
            for(j=i+1;j<n;j++)
            {
                int t = a[i], r = a[j];
                if(t < r)
                    swap(t, r);
                int p = gcd(t, r);
                if(p == 1)
                    c++;
                b++;
            }
        }
        if(c == 0)
            cout << "No estimate for this data set." << endl;
        else
        {
            cout << showpoint;
            cout << fixed;
            cout << setprecision(6);
            double t = sqrt(((double)b*6.0)/double(c));
            cout << t << endl;
        }
    }
    return 0;
}

Comments